1 /* ad.c - routines for dealing with attribute descriptions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
23 #include <ac/socket.h>
24 #include <ac/string.h>
30 static AttributeName anlist_no_attrs[] = {
31 { BER_BVC( LDAP_NO_ATTRS ), NULL, 0, NULL },
32 { BER_BVNULL, NULL, 0, NULL }
35 static AttributeName anlist_all_user_attributes[] = {
36 { BER_BVC( LDAP_ALL_USER_ATTRIBUTES ), NULL, 0, NULL },
37 { BER_BVNULL, NULL, 0, NULL }
40 static AttributeName anlist_all_operational_attributes[] = {
41 { BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES ), NULL, 0, NULL },
42 { BER_BVNULL, NULL, 0, NULL }
45 static AttributeName anlist_all_attributes[] = {
46 { BER_BVC( LDAP_ALL_USER_ATTRIBUTES ), NULL, 0, NULL },
47 { BER_BVC( LDAP_ALL_OPERATIONAL_ATTRIBUTES ), NULL, 0, NULL },
48 { BER_BVNULL, NULL, 0, NULL }
51 AttributeName *slap_anlist_no_attrs = anlist_no_attrs;
52 AttributeName *slap_anlist_all_user_attributes = anlist_all_user_attributes;
53 AttributeName *slap_anlist_all_operational_attributes = anlist_all_operational_attributes;
54 AttributeName *slap_anlist_all_attributes = anlist_all_attributes;
56 typedef struct Attr_option {
57 struct berval name; /* option name or prefix */
58 int prefix; /* NAME is a tag and range prefix */
61 /* Options sorted by name, and number of options */
62 static Attr_option internal_options[] = {
63 { { sizeof("lang-")-1, "lang-" }, 1 },
64 { { sizeof("range=")-1, "range=" }, 1 } };
66 static Attr_option *options = internal_options;
67 static int option_count = 2;
69 static Attr_option *ad_find_option_definition( const char *opt, int optlen );
71 static int ad_keystring(
76 if( !AD_LEADCHAR( bv->bv_val[0] ) ) {
80 for( i=1; i<bv->bv_len; i++ ) {
81 if( !AD_CHAR( bv->bv_val[i] ) ) {
88 void ad_destroy( AttributeDescription *ad )
90 AttributeDescription *n;
92 for (; ad != NULL; ad = n) {
98 /* Is there an AttributeDescription for this type that uses these tags? */
99 AttributeDescription * ad_find_tags(
101 struct berval *tags )
103 AttributeDescription *ad;
105 ldap_pvt_thread_mutex_lock( &type->sat_ad_mutex );
106 for (ad = type->sat_ad; ad; ad=ad->ad_next)
108 if (ad->ad_tags.bv_len == tags->bv_len &&
109 !strcasecmp(ad->ad_tags.bv_val, tags->bv_val))
112 ldap_pvt_thread_mutex_unlock( &type->sat_ad_mutex );
118 AttributeDescription **ad,
122 bv.bv_val = (char *) str;
123 bv.bv_len = strlen( str );
125 return slap_bv2ad( &bv, ad, text );
128 static char *strchrlen(
135 for( i=0; p[i]; i++ ) {
138 return (char *) &p[i];
148 AttributeDescription **ad,
151 int rtn = LDAP_UNDEFINED_TYPE;
152 AttributeDescription desc, *d2;
153 char *name, *options;
158 /* hardcoded limits for speed */
159 #define MAX_TAGGING_OPTIONS 128
160 struct berval tags[MAX_TAGGING_OPTIONS+1];
161 #define MAX_TAGS_LEN 1024
162 char tagbuf[MAX_TAGS_LEN];
164 assert( ad != NULL );
165 assert( *ad == NULL ); /* temporary */
167 if( bv == NULL || BER_BVISNULL( bv ) || BER_BVISEMPTY( bv ) ) {
168 *text = "empty AttributeDescription";
172 /* make sure description is IA5 */
173 if( ad_keystring( bv ) ) {
174 *text = "AttributeDescription contains inappropriate characters";
178 /* find valid base attribute type; parse in place */
179 memset( &desc, 0, sizeof( desc ));
182 options = strchr(name, ';');
183 if( options != NULL ) {
184 desc.ad_cname.bv_len = options - name;
186 desc.ad_type = at_bvfind( &desc.ad_cname );
187 if( desc.ad_type == NULL ) {
188 *text = "attribute type undefined";
192 if( is_at_operational( desc.ad_type ) && options != NULL ) {
193 *text = "operational attribute with options undefined";
198 * parse options in place
201 memset( tags, 0, sizeof( tags ));
204 for( opt=options; opt != NULL; opt=next ) {
207 next = strchrlen( opt, ';', &optlen );
210 *text = "zero length option is invalid";
213 } else if ( optlen == sizeof("binary")-1 &&
214 strncasecmp( opt, "binary", sizeof("binary")-1 ) == 0 )
217 if( slap_ad_is_binary( &desc ) ) {
218 *text = "option \"binary\" specified multiple times";
222 if( !slap_syntax_is_binary( desc.ad_type->sat_syntax )) {
223 /* not stored in binary, disallow option */
224 *text = "option \"binary\" not supported with type";
228 desc.ad_flags |= SLAP_DESC_BINARY;
231 } else if ( ad_find_option_definition( opt, optlen ) ) {
234 if( opt[optlen-1] == '-' ) {
235 desc.ad_flags |= SLAP_DESC_TAG_RANGE;
238 if( ntags >= MAX_TAGGING_OPTIONS ) {
239 *text = "too many tagging options";
244 * tags should be presented in sorted order,
245 * so run the array in reverse.
247 for( i=ntags-1; i>=0; i-- ) {
250 rc = strncasecmp( opt, tags[i].bv_val,
251 (unsigned) optlen < tags[i].bv_len
252 ? optlen : tags[i].bv_len );
254 if( rc == 0 && (unsigned)optlen == tags[i].bv_len ) {
255 /* duplicate (ignore) */
258 } else if ( rc > 0 ||
259 ( rc == 0 && (unsigned)optlen > tags[i].bv_len ))
261 AC_MEMCPY( &tags[i+2], &tags[i+1],
262 (ntags-i-1)*sizeof(struct berval) );
263 tags[i+1].bv_val = opt;
264 tags[i+1].bv_len = optlen;
270 AC_MEMCPY( &tags[1], &tags[0],
271 ntags*sizeof(struct berval) );
273 tags[0].bv_val = opt;
274 tags[0].bv_len = optlen;
277 tagslen += optlen + 1;
281 *text = "unrecognized option";
289 if( tagslen > MAX_TAGS_LEN ) {
290 *text = "tagging options too long";
294 desc.ad_tags.bv_val = tagbuf;
297 for( i=0; i<ntags; i++ ) {
298 AC_MEMCPY( &desc.ad_tags.bv_val[tagslen],
299 tags[i].bv_val, tags[i].bv_len );
301 tagslen += tags[i].bv_len;
302 desc.ad_tags.bv_val[tagslen++] = ';';
305 desc.ad_tags.bv_val[--tagslen] = '\0';
306 desc.ad_tags.bv_len = tagslen;
309 /* see if a matching description is already cached */
310 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
311 if( d2->ad_flags != desc.ad_flags ) {
314 if( d2->ad_tags.bv_len != desc.ad_tags.bv_len ) {
317 if( d2->ad_tags.bv_len == 0 ) {
320 if( strncasecmp( d2->ad_tags.bv_val, desc.ad_tags.bv_val,
321 desc.ad_tags.bv_len ) == 0 )
327 /* Not found, add new one */
330 ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
331 /* check again now that we've locked */
332 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
333 if (d2->ad_flags != desc.ad_flags)
335 if (d2->ad_tags.bv_len != desc.ad_tags.bv_len)
337 if (d2->ad_tags.bv_len == 0)
339 if (strncasecmp(d2->ad_tags.bv_val, desc.ad_tags.bv_val,
340 desc.ad_tags.bv_len) == 0)
344 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
348 /* Allocate a single contiguous block. If there are no
349 * options, we just need space for the AttrDesc structure.
350 * Otherwise, we need to tack on the full name length +
351 * options length, + maybe tagging options length again.
353 if (desc.ad_tags.bv_len || desc.ad_flags != SLAP_DESC_NONE) {
354 dlen = desc.ad_type->sat_cname.bv_len + 1;
355 if (desc.ad_tags.bv_len) {
356 dlen += 1+desc.ad_tags.bv_len;
358 if( slap_ad_is_binary( &desc ) ) {
359 dlen += sizeof(";binary")+desc.ad_tags.bv_len;
363 d2 = ch_malloc(sizeof(AttributeDescription) + dlen);
365 d2->ad_type = desc.ad_type;
366 d2->ad_flags = desc.ad_flags;
367 d2->ad_cname.bv_len = desc.ad_type->sat_cname.bv_len;
368 d2->ad_tags.bv_len = desc.ad_tags.bv_len;
371 d2->ad_cname.bv_val = d2->ad_type->sat_cname.bv_val;
372 d2->ad_tags.bv_val = NULL;
376 d2->ad_cname.bv_val = (char *)(d2+1);
377 strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname.bv_val);
378 cp = d2->ad_cname.bv_val + d2->ad_cname.bv_len;
379 if( slap_ad_is_binary( &desc ) ) {
382 if( desc.ad_tags.bv_len ) {
383 lp = desc.ad_tags.bv_val;
384 while( strncasecmp(lp, "binary", sizeof("binary")-1) < 0
385 && (lp = strchr( lp, ';' )) != NULL )
387 if( lp != desc.ad_tags.bv_val ) {
390 ? lp - desc.ad_tags.bv_val - 1
391 : strlen( desc.ad_tags.bv_val ));
392 cp = lutil_strncopy(cp, desc.ad_tags.bv_val, j);
395 cp = lutil_strcopy(cp, ";binary");
398 cp = lutil_strcopy(cp, lp);
400 d2->ad_cname.bv_len = cp - d2->ad_cname.bv_val;
401 if( desc.ad_tags.bv_len )
402 ldap_pvt_str2lower(op);
407 if( desc.ad_tags.bv_len ) {
408 lp = d2->ad_cname.bv_val + d2->ad_cname.bv_len + j;
411 d2->ad_tags.bv_val = lp;
412 strcpy(lp, desc.ad_tags.bv_val);
413 ldap_pvt_str2lower(lp);
415 d2->ad_cname.bv_len += 1 + desc.ad_tags.bv_len;
418 /* Add new desc to list. We always want the bare Desc with
419 * no options to stay at the head of the list, assuming
420 * that one will be used most frequently.
422 if (desc.ad_type->sat_ad == NULL || dlen == 0) {
423 d2->ad_next = desc.ad_type->sat_ad;
424 desc.ad_type->sat_ad = d2;
426 d2->ad_next = desc.ad_type->sat_ad->ad_next;
427 desc.ad_type->sat_ad->ad_next = d2;
429 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
441 static int is_ad_subtags(
442 struct berval *subtagsbv,
443 struct berval *suptagsbv )
445 const char *suptags, *supp, *supdelimp;
446 const char *subtags, *subp, *subdelimp;
449 subtags =subtagsbv->bv_val;
450 suptags =suptagsbv->bv_val;
452 for( supp=suptags ; supp; supp=supdelimp ) {
453 supdelimp = strchrlen( supp, ';', &suplen );
454 if( supdelimp ) supdelimp++;
456 for( subp=subtags ; subp; subp=subdelimp ) {
457 subdelimp = strchrlen( subp, ';', &sublen );
458 if( subdelimp ) subdelimp++;
461 ? ( suplen-1 == sublen && supp[suplen-1] == '-'
462 && strncmp( supp, subp, sublen ) == 0 )
463 : ( ( suplen == sublen || supp[suplen-1] == '-' )
464 && strncmp( supp, subp, suplen ) == 0 ) )
477 AttributeDescription *sub,
478 AttributeDescription *super
484 for ( a = sub->ad_type; a; a=a->sat_sup ) {
485 if ( a == super->ad_type ) break;
491 /* ensure sub does support all flags of super */
492 lr = sub->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
493 if(( super->ad_flags & ( sub->ad_flags | lr )) != super->ad_flags ) {
497 /* check for tagging options */
498 if ( super->ad_tags.bv_len == 0 )
500 if ( sub->ad_tags.bv_len == 0 )
503 return is_ad_subtags( &sub->ad_tags, &super->ad_tags );
507 AttributeDescription *desc,
508 AttributeName *attrs )
510 if (! attrs ) return 0;
512 for( ; attrs->an_name.bv_val; attrs++ ) {
516 if ( attrs->an_desc ) {
519 if ( desc == attrs->an_desc ) {
524 * EXTENSION: if requested description is preceeded by
525 * a '-' character, do not match on subtypes.
527 if ( attrs->an_name.bv_val[0] == '-' ) {
531 /* Is this a subtype of the requested attr? */
532 for (a = desc->ad_type; a; a=a->sat_sup) {
533 if ( a == attrs->an_desc->ad_type )
539 /* Does desc support all the requested flags? */
540 lr = desc->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
541 if(( attrs->an_desc->ad_flags & (desc->ad_flags | lr))
542 != attrs->an_desc->ad_flags ) {
545 /* Do the descs have compatible tags? */
546 if ( attrs->an_desc->ad_tags.bv_len == 0 ) {
549 if ( desc->ad_tags.bv_len == 0) {
552 if ( is_ad_subtags( &desc->ad_tags,
553 &attrs->an_desc->ad_tags ) ) {
560 * EXTENSION: see if requested description is @objectClass
561 * if so, return attributes which the class requires/allows
562 * else if requested description is !objectClass, return
563 * attributes which the class does not require/allow
566 if( oc == NULL && attrs->an_name.bv_val ) {
567 switch( attrs->an_name.bv_val[0] ) {
568 case '@': /* @objectClass */
569 case '+': /* +objectClass (deprecated) */
570 case '!': { /* exclude */
571 struct berval ocname;
572 ocname.bv_len = attrs->an_name.bv_len - 1;
573 ocname.bv_val = &attrs->an_name.bv_val[1];
574 oc = oc_bvfind( &ocname );
575 attrs->an_oc_exclude = 0;
576 if ( oc && attrs->an_name.bv_val[0] == '!' ) {
577 attrs->an_oc_exclude = 1;
581 default: /* old (deprecated) way */
582 oc = oc_bvfind( &attrs->an_name );
587 if ( attrs->an_oc_exclude ) {
588 if ( oc == slap_schema.si_oc_extensibleObject ) {
589 /* extensibleObject allows the return of anything */
593 if( oc->soc_required ) {
594 /* allow return of required attributes */
597 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
598 for (a = desc->ad_type; a; a=a->sat_sup) {
599 if ( a == oc->soc_required[i] ) {
606 if( oc->soc_allowed ) {
607 /* allow return of allowed attributes */
609 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
610 for (a = desc->ad_type; a; a=a->sat_sup) {
611 if ( a == oc->soc_allowed[i] ) {
621 if ( oc == slap_schema.si_oc_extensibleObject ) {
622 /* extensibleObject allows the return of anything */
626 if( oc->soc_required ) {
627 /* allow return of required attributes */
630 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
631 for (a = desc->ad_type; a; a=a->sat_sup) {
632 if ( a == oc->soc_required[i] ) {
639 if( oc->soc_allowed ) {
640 /* allow return of allowed attributes */
642 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
643 for (a = desc->ad_type; a; a=a->sat_sup) {
644 if ( a == oc->soc_allowed[i] ) {
652 /* short-circuit this search next time around */
653 if (!slap_schema.si_at_undefined->sat_ad) {
655 slap_bv2undef_ad(&attrs->an_name,
656 &attrs->an_desc, &text);
659 slap_schema.si_at_undefined->sat_ad;
668 int slap_str2undef_ad(
670 AttributeDescription **ad,
674 bv.bv_val = (char *) str;
675 bv.bv_len = strlen( str );
677 return slap_bv2undef_ad( &bv, ad, text );
680 int slap_bv2undef_ad(
682 AttributeDescription **ad,
685 AttributeDescription *desc;
687 assert( ad != NULL );
689 if( bv == NULL || bv->bv_len == 0 ) {
690 *text = "empty AttributeDescription";
691 return LDAP_UNDEFINED_TYPE;
694 /* make sure description is IA5 */
695 if( ad_keystring( bv ) ) {
696 *text = "AttributeDescription contains inappropriate characters";
697 return LDAP_UNDEFINED_TYPE;
700 for( desc = slap_schema.si_at_undefined->sat_ad; desc;
703 if( desc->ad_cname.bv_len == bv->bv_len &&
704 !strcasecmp( desc->ad_cname.bv_val, bv->bv_val ))
711 desc = ch_malloc(sizeof(AttributeDescription) + 1 +
714 desc->ad_flags = SLAP_DESC_NONE;
715 desc->ad_tags.bv_val = NULL;
716 desc->ad_tags.bv_len = 0;
718 desc->ad_cname.bv_len = bv->bv_len;
719 desc->ad_cname.bv_val = (char *)(desc+1);
720 strcpy(desc->ad_cname.bv_val, bv->bv_val);
722 /* canonical to upper case */
723 ldap_pvt_str2upper( desc->ad_cname.bv_val );
725 desc->ad_type = slap_schema.si_at_undefined;
726 desc->ad_next = desc->ad_type->sat_ad;
727 desc->ad_type->sat_ad = desc;
745 if( a == NULL ) return 0;
747 for ( ; a->an_name.bv_val; a++ ) {
748 if ( a->an_name.bv_len != s->bv_len) continue;
749 if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) {
758 * Convert a delimited string into a list of AttributeNames; add
759 * on to an existing list if it was given. If the string is not
760 * a valid attribute name, if a '-' is prepended it is skipped
761 * and the remaining name is tried again; if a '@' (or '+') is
762 * prepended, an objectclass name is searched instead; if a '!'
763 * is prepended, the objectclass name is negated.
765 * NOTE: currently, if a valid attribute name is not found, the
766 * same string is also checked as valid objectclass name; however,
767 * this behavior is deprecated.
770 str2anlist( AttributeName *an, char *in, const char *brkstr )
779 /* find last element in list */
780 for (i = 0; an && an[i].an_name.bv_val; i++);
782 /* protect the input string from strtok */
783 str = ch_strdup( in );
785 /* Count words in string */
787 for ( s = str; *s; s++ ) {
788 if ( strchr( brkstr, *s ) != NULL ) {
793 an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
794 BER_BVZERO( &an[i + j].an_name );
796 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
798 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
800 anew->an_desc = NULL;
802 anew->an_oc_exclude = 0;
803 ber_str2bv(s, 0, 1, &anew->an_name);
804 slap_bv2ad(&anew->an_name, &anew->an_desc, &text);
805 if ( !anew->an_desc ) {
806 switch( anew->an_name.bv_val[0] ) {
808 struct berval adname;
809 adname.bv_len = anew->an_name.bv_len - 1;
810 adname.bv_val = &anew->an_name.bv_val[1];
811 slap_bv2ad(&adname, &anew->an_desc, &text);
812 if ( !anew->an_desc ) {
818 case '+': /* (deprecated) */
820 struct berval ocname;
821 ocname.bv_len = anew->an_name.bv_len - 1;
822 ocname.bv_val = &anew->an_name.bv_val[1];
823 anew->an_oc = oc_bvfind( &ocname );
824 if ( !anew->an_oc ) {
828 if ( anew->an_name.bv_val[0] == '!' ) {
829 anew->an_oc_exclude = 1;
834 /* old (deprecated) way */
835 anew->an_oc = oc_bvfind( &anew->an_name );
836 if ( !anew->an_oc ) {
844 anew->an_name.bv_val = NULL;
849 for ( i = 0; an[i].an_name.bv_val; i++ ) {
850 free( an[i].an_name.bv_val );
854 * overwrites input string
862 char **anlist2charray_x( AttributeName *an, int dup, void *ctx )
868 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
870 attrs = (char **) slap_sl_malloc( (i + 1) * sizeof(char *), ctx );
871 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
873 attrs[i] = ch_strdup( an[i].an_name.bv_val );
875 attrs[i] = an[i].an_name.bv_val;
885 char **anlist2charray( AttributeName *an, int dup )
887 return anlist2charray_x( an, dup, NULL );
891 anlist2attrs( AttributeName * anlist )
898 attrs = anlist2charray( anlist, 1 );
900 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
901 if ( ( oc = anlist[i].an_oc ) ) {
902 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) ;
904 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) ;
915 attrs = (char **) ch_realloc( attrs, (i + k + 1) * sizeof( char * ));
917 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
918 if ( ( oc = anlist[i].an_oc ) ) {
919 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) {
920 attrs[n++] = ch_strdup(
921 oc->soc_required[j]->sat_cname.bv_val );
923 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) {
924 attrs[n++] = ch_strdup(
925 oc->soc_allowed[j]->sat_cname.bv_val );
934 while ( attrs && attrs[i] ) {
935 if ( *attrs[i] == '@' ) {
936 for ( j = i; attrs[j]; j++ ) {
939 attrs[j] = attrs[j+1];
946 for ( i = 0; attrs && attrs[i]; i++ ) {
948 while ( attrs && attrs[j] ) {
949 if ( !strcmp( attrs[i], attrs[j] )) {
950 for ( k = j; attrs && attrs[k]; k++ ) {
953 attrs[k] = attrs[k+1];
962 attrs = (char **) ch_realloc( attrs, (i+1) * sizeof( char * ));
969 file2anlist( AttributeName *an, const char *fname, const char *brkstr )
975 size_t lmax = LBUFSIZ;
977 fp = fopen( fname, "r" );
979 Debug( LDAP_DEBUG_ANY,
980 "get_attrs_from_file: failed to open attribute list file "
981 "\"%s\": %s\n", fname, strerror(errno), 0 );
985 lcur = line = (char *) ch_malloc( lmax );
987 Debug( LDAP_DEBUG_ANY,
988 "get_attrs_from_file: could not allocate memory\n",
994 while ( fgets( lcur, LBUFSIZ, fp ) != NULL ) {
995 if ( ( c = strchr( lcur, '\n' ) ) ) {
998 } else if ( *(c-1) == '\r' ) {
1005 line = (char *) ch_realloc( line, lmax );
1007 Debug( LDAP_DEBUG_ANY,
1008 "get_attrs_from_file: could not allocate memory\n",
1013 lcur = line + strlen( line );
1016 an = str2anlist( an, line, brkstr );
1027 /* Define an attribute option. */
1029 ad_define_option( const char *name, const char *fname, int lineno )
1032 unsigned int optlen;
1034 if ( options == internal_options ) {
1043 if ( !DESC_CHAR( name[optlen] ) ) {
1044 Debug( LDAP_DEBUG_ANY,
1045 "%s: line %d: illegal option name \"%s\"\n",
1046 fname, lineno, name );
1049 } while ( name[++optlen] );
1051 options = ch_realloc( options,
1052 (option_count+1) * sizeof(Attr_option) );
1054 if ( strcasecmp( name, "binary" ) == 0
1055 || ad_find_option_definition( name, optlen ) ) {
1056 Debug( LDAP_DEBUG_ANY,
1057 "%s: line %d: option \"%s\" is already defined\n",
1058 fname, lineno, name );
1062 for ( i = option_count; i; --i ) {
1063 if ( strcasecmp( name, options[i-1].name.bv_val ) >= 0 )
1065 options[i] = options[i-1];
1068 options[i].name.bv_val = ch_strdup( name );
1069 options[i].name.bv_len = optlen;
1070 options[i].prefix = (name[optlen-1] == '-');
1072 if ( i != option_count &&
1073 options[i].prefix &&
1074 optlen < options[i+1].name.bv_len &&
1075 strncasecmp( name, options[i+1].name.bv_val, optlen ) == 0 ) {
1076 Debug( LDAP_DEBUG_ANY,
1077 "%s: line %d: option \"%s\" overrides previous option\n",
1078 fname, lineno, name );
1086 /* Find the definition of the option name or prefix matching the arguments */
1087 static Attr_option *
1088 ad_find_option_definition( const char *opt, int optlen )
1090 int top = 0, bot = option_count;
1091 while ( top < bot ) {
1092 int mid = (top + bot) / 2;
1093 int mlen = options[mid].name.bv_len;
1094 char *mname = options[mid].name.bv_val;
1096 if ( optlen < mlen ) {
1097 j = strncasecmp( opt, mname, optlen ) - 1;
1099 j = strncasecmp( opt, mname, mlen );
1100 if ( j==0 && (optlen==mlen || options[mid].prefix) )
1101 return &options[mid];
1111 MatchingRule *ad_mr(
1112 AttributeDescription *ad,
1115 switch( usage & SLAP_MR_TYPE_MASK ) {
1117 case SLAP_MR_EQUALITY:
1118 return ad->ad_type->sat_equality;
1120 case SLAP_MR_ORDERING:
1121 return ad->ad_type->sat_ordering;
1123 case SLAP_MR_SUBSTR:
1124 return ad->ad_type->sat_substr;
1128 assert( 0 /* ad_mr: bad usage */);