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 static Attr_option lang_option = { { sizeof("lang-")-1, "lang-" }, 1 };
63 /* Options sorted by name, and number of options */
64 static Attr_option *options = &lang_option;
65 static int option_count = 1;
67 static Attr_option *ad_find_option_definition( const char *opt, int optlen );
69 static int ad_keystring(
74 if( !AD_LEADCHAR( bv->bv_val[0] ) ) {
78 for( i=1; i<bv->bv_len; i++ ) {
79 if( !AD_CHAR( bv->bv_val[i] ) ) {
86 void ad_destroy( AttributeDescription *ad )
88 AttributeDescription *n;
90 for (; ad != NULL; ad = n) {
96 /* Is there an AttributeDescription for this type that uses these tags? */
97 AttributeDescription * ad_find_tags(
101 AttributeDescription *ad;
103 ldap_pvt_thread_mutex_lock( &type->sat_ad_mutex );
104 for (ad = type->sat_ad; ad; ad=ad->ad_next)
106 if (ad->ad_tags.bv_len == tags->bv_len &&
107 !strcasecmp(ad->ad_tags.bv_val, tags->bv_val))
110 ldap_pvt_thread_mutex_unlock( &type->sat_ad_mutex );
116 AttributeDescription **ad,
120 bv.bv_val = (char *) str;
121 bv.bv_len = strlen( str );
123 return slap_bv2ad( &bv, ad, text );
126 static char *strchrlen(
133 for( i=0; p[i]; i++ ) {
136 return (char *) &p[i];
146 AttributeDescription **ad,
149 int rtn = LDAP_UNDEFINED_TYPE;
150 AttributeDescription desc, *d2;
151 char *name, *options;
156 /* hardcoded limits for speed */
157 #define MAX_TAGGING_OPTIONS 128
158 struct berval tags[MAX_TAGGING_OPTIONS+1];
159 #define MAX_TAGS_LEN 1024
160 char tagbuf[MAX_TAGS_LEN];
162 assert( ad != NULL );
163 assert( *ad == NULL ); /* temporary */
165 if( bv == NULL || BER_BVISNULL( bv ) || BER_BVISEMPTY( bv ) ) {
166 *text = "empty AttributeDescription";
170 /* make sure description is IA5 */
171 if( ad_keystring( bv ) ) {
172 *text = "AttributeDescription contains inappropriate characters";
176 /* find valid base attribute type; parse in place */
177 memset( &desc, 0, sizeof( desc ));
180 options = strchr(name, ';');
181 if( options != NULL ) {
182 desc.ad_cname.bv_len = options - name;
184 desc.ad_type = at_bvfind( &desc.ad_cname );
185 if( desc.ad_type == NULL ) {
186 *text = "attribute type undefined";
190 if( is_at_operational( desc.ad_type ) && options != NULL ) {
191 *text = "operational attribute with options undefined";
196 * parse options in place
199 memset( tags, 0, sizeof( tags ));
202 for( opt=options; opt != NULL; opt=next ) {
205 next = strchrlen( opt, ';', &optlen );
208 *text = "zero length option is invalid";
211 } else if ( optlen == sizeof("binary")-1 &&
212 strncasecmp( opt, "binary", sizeof("binary")-1 ) == 0 )
215 if( slap_ad_is_binary( &desc ) ) {
216 *text = "option \"binary\" specified multiple times";
220 if( !slap_syntax_is_binary( desc.ad_type->sat_syntax )) {
221 /* not stored in binary, disallow option */
222 *text = "option \"binary\" not supported with type";
226 desc.ad_flags |= SLAP_DESC_BINARY;
229 } else if ( ad_find_option_definition( opt, optlen ) ) {
232 if( opt[optlen-1] == '-' ) {
233 desc.ad_flags |= SLAP_DESC_TAG_RANGE;
236 if( ntags >= MAX_TAGGING_OPTIONS ) {
237 *text = "too many tagging options";
242 * tags should be presented in sorted order,
243 * so run the array in reverse.
245 for( i=ntags-1; i>=0; i-- ) {
248 rc = strncasecmp( opt, tags[i].bv_val,
249 (unsigned) optlen < tags[i].bv_len
250 ? optlen : tags[i].bv_len );
252 if( rc == 0 && (unsigned)optlen == tags[i].bv_len ) {
253 /* duplicate (ignore) */
256 } else if ( rc > 0 ||
257 ( rc == 0 && (unsigned)optlen > tags[i].bv_len ))
259 AC_MEMCPY( &tags[i+2], &tags[i+1],
260 (ntags-i-1)*sizeof(struct berval) );
261 tags[i+1].bv_val = opt;
262 tags[i+1].bv_len = optlen;
268 AC_MEMCPY( &tags[1], &tags[0],
269 ntags*sizeof(struct berval) );
271 tags[0].bv_val = opt;
272 tags[0].bv_len = optlen;
275 tagslen += optlen + 1;
279 *text = "unrecognized option";
287 if( tagslen > MAX_TAGS_LEN ) {
288 *text = "tagging options too long";
292 desc.ad_tags.bv_val = tagbuf;
295 for( i=0; i<ntags; i++ ) {
296 AC_MEMCPY( &desc.ad_tags.bv_val[tagslen],
297 tags[i].bv_val, tags[i].bv_len );
299 tagslen += tags[i].bv_len;
300 desc.ad_tags.bv_val[tagslen++] = ';';
303 desc.ad_tags.bv_val[--tagslen] = '\0';
304 desc.ad_tags.bv_len = tagslen;
307 /* see if a matching description is already cached */
308 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
309 if( d2->ad_flags != desc.ad_flags ) {
312 if( d2->ad_tags.bv_len != desc.ad_tags.bv_len ) {
315 if( d2->ad_tags.bv_len == 0 ) {
318 if( strncasecmp( d2->ad_tags.bv_val, desc.ad_tags.bv_val,
319 desc.ad_tags.bv_len ) == 0 )
325 /* Not found, add new one */
328 ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
329 /* check again now that we've locked */
330 for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
331 if (d2->ad_flags != desc.ad_flags)
333 if (d2->ad_tags.bv_len != desc.ad_tags.bv_len)
335 if (d2->ad_tags.bv_len == 0)
337 if (strncasecmp(d2->ad_tags.bv_val, desc.ad_tags.bv_val,
338 desc.ad_tags.bv_len) == 0)
342 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
346 /* Allocate a single contiguous block. If there are no
347 * options, we just need space for the AttrDesc structure.
348 * Otherwise, we need to tack on the full name length +
349 * options length, + maybe tagging options length again.
351 if (desc.ad_tags.bv_len || desc.ad_flags != SLAP_DESC_NONE) {
352 dlen = desc.ad_type->sat_cname.bv_len + 1;
353 if (desc.ad_tags.bv_len) {
354 dlen += 1+desc.ad_tags.bv_len;
356 if( slap_ad_is_binary( &desc ) ) {
357 dlen += sizeof(";binary")+desc.ad_tags.bv_len;
361 d2 = ch_malloc(sizeof(AttributeDescription) + dlen);
363 d2->ad_type = desc.ad_type;
364 d2->ad_flags = desc.ad_flags;
365 d2->ad_cname.bv_len = desc.ad_type->sat_cname.bv_len;
366 d2->ad_tags.bv_len = desc.ad_tags.bv_len;
369 d2->ad_cname.bv_val = d2->ad_type->sat_cname.bv_val;
370 d2->ad_tags.bv_val = NULL;
374 d2->ad_cname.bv_val = (char *)(d2+1);
375 strcpy(d2->ad_cname.bv_val, d2->ad_type->sat_cname.bv_val);
376 cp = d2->ad_cname.bv_val + d2->ad_cname.bv_len;
377 if( slap_ad_is_binary( &desc ) ) {
380 if( desc.ad_tags.bv_len ) {
381 lp = desc.ad_tags.bv_val;
382 while( strncasecmp(lp, "binary", sizeof("binary")-1) < 0
383 && (lp = strchr( lp, ';' )) != NULL )
385 if( lp != desc.ad_tags.bv_val ) {
388 ? lp - desc.ad_tags.bv_val - 1
389 : strlen( desc.ad_tags.bv_val ));
390 cp = lutil_strncopy(cp, desc.ad_tags.bv_val, j);
393 cp = lutil_strcopy(cp, ";binary");
396 cp = lutil_strcopy(cp, lp);
398 d2->ad_cname.bv_len = cp - d2->ad_cname.bv_val;
399 if( desc.ad_tags.bv_len )
400 ldap_pvt_str2lower(op);
405 if( desc.ad_tags.bv_len ) {
406 lp = d2->ad_cname.bv_val + d2->ad_cname.bv_len + j;
409 d2->ad_tags.bv_val = lp;
410 strcpy(lp, desc.ad_tags.bv_val);
411 ldap_pvt_str2lower(lp);
413 d2->ad_cname.bv_len += 1 + desc.ad_tags.bv_len;
416 /* Add new desc to list. We always want the bare Desc with
417 * no options to stay at the head of the list, assuming
418 * that one will be used most frequently.
420 if (desc.ad_type->sat_ad == NULL || dlen == 0) {
421 d2->ad_next = desc.ad_type->sat_ad;
422 desc.ad_type->sat_ad = d2;
424 d2->ad_next = desc.ad_type->sat_ad->ad_next;
425 desc.ad_type->sat_ad->ad_next = d2;
427 ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
439 static int is_ad_subtags(
440 struct berval *subtagsbv,
441 struct berval *suptagsbv )
443 const char *suptags, *supp, *supdelimp;
444 const char *subtags, *subp, *subdelimp;
447 subtags =subtagsbv->bv_val;
448 suptags =suptagsbv->bv_val;
450 for( supp=suptags ; supp; supp=supdelimp ) {
451 supdelimp = strchrlen( supp, ';', &suplen );
452 if( supdelimp ) supdelimp++;
454 for( subp=subtags ; subp; subp=subdelimp ) {
455 subdelimp = strchrlen( subp, ';', &sublen );
456 if( subdelimp ) subdelimp++;
459 ? ( suplen-1 == sublen && supp[suplen-1] == '-'
460 && strncmp( supp, subp, sublen ) == 0 )
461 : ( ( suplen == sublen || supp[suplen-1] == '-' )
462 && strncmp( supp, subp, suplen ) == 0 ) )
475 AttributeDescription *sub,
476 AttributeDescription *super
482 for ( a = sub->ad_type; a; a=a->sat_sup ) {
483 if ( a == super->ad_type ) break;
489 /* ensure sub does support all flags of super */
490 lr = sub->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
491 if(( super->ad_flags & ( sub->ad_flags | lr )) != super->ad_flags ) {
495 /* check for tagging options */
496 if ( super->ad_tags.bv_len == 0 )
498 if ( sub->ad_tags.bv_len == 0 )
501 return is_ad_subtags( &sub->ad_tags, &super->ad_tags );
505 AttributeDescription *desc,
506 AttributeName *attrs )
508 if (! attrs ) return 0;
510 for( ; attrs->an_name.bv_val; attrs++ ) {
514 if ( attrs->an_desc ) {
517 if ( desc == attrs->an_desc ) {
522 * EXTENSION: if requested description is preceeded by
523 * a '-' character, do not match on subtypes.
525 if ( attrs->an_name.bv_val[0] == '-' ) {
529 /* Is this a subtype of the requested attr? */
530 for (a = desc->ad_type; a; a=a->sat_sup) {
531 if ( a == attrs->an_desc->ad_type )
537 /* Does desc support all the requested flags? */
538 lr = desc->ad_tags.bv_len ? SLAP_DESC_TAG_RANGE : 0;
539 if(( attrs->an_desc->ad_flags & (desc->ad_flags | lr))
540 != attrs->an_desc->ad_flags ) {
543 /* Do the descs have compatible tags? */
544 if ( attrs->an_desc->ad_tags.bv_len == 0 ) {
547 if ( desc->ad_tags.bv_len == 0) {
550 if ( is_ad_subtags( &desc->ad_tags,
551 &attrs->an_desc->ad_tags ) ) {
558 * EXTENSION: see if requested description is @objectClass
559 * if so, return attributes which the class requires/allows
560 * else if requested description is !objectClass, return
561 * attributes which the class does not require/allow
564 if( oc == NULL && attrs->an_name.bv_val ) {
565 switch( attrs->an_name.bv_val[0] ) {
566 case '@': /* @objectClass */
567 case '+': /* +objectClass (deprecated) */
568 case '!': { /* exclude */
569 struct berval ocname;
570 ocname.bv_len = attrs->an_name.bv_len - 1;
571 ocname.bv_val = &attrs->an_name.bv_val[1];
572 oc = oc_bvfind( &ocname );
573 attrs->an_oc_exclude = 0;
574 if ( oc && attrs->an_name.bv_val[0] == '!' ) {
575 attrs->an_oc_exclude = 1;
579 default: /* old (deprecated) way */
580 oc = oc_bvfind( &attrs->an_name );
585 if ( attrs->an_oc_exclude ) {
586 if ( oc == slap_schema.si_oc_extensibleObject ) {
587 /* extensibleObject allows the return of anything */
591 if( oc->soc_required ) {
592 /* allow return of required attributes */
595 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
596 for (a = desc->ad_type; a; a=a->sat_sup) {
597 if ( a == oc->soc_required[i] ) {
604 if( oc->soc_allowed ) {
605 /* allow return of allowed attributes */
607 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
608 for (a = desc->ad_type; a; a=a->sat_sup) {
609 if ( a == oc->soc_allowed[i] ) {
619 if ( oc == slap_schema.si_oc_extensibleObject ) {
620 /* extensibleObject allows the return of anything */
624 if( oc->soc_required ) {
625 /* allow return of required attributes */
628 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
629 for (a = desc->ad_type; a; a=a->sat_sup) {
630 if ( a == oc->soc_required[i] ) {
637 if( oc->soc_allowed ) {
638 /* allow return of allowed attributes */
640 for ( i = 0; oc->soc_allowed[i] != NULL; i++ ) {
641 for (a = desc->ad_type; a; a=a->sat_sup) {
642 if ( a == oc->soc_allowed[i] ) {
650 /* short-circuit this search next time around */
651 if (!slap_schema.si_at_undefined->sat_ad) {
653 slap_bv2undef_ad(&attrs->an_name,
654 &attrs->an_desc, &text);
657 slap_schema.si_at_undefined->sat_ad;
666 int slap_str2undef_ad(
668 AttributeDescription **ad,
672 bv.bv_val = (char *) str;
673 bv.bv_len = strlen( str );
675 return slap_bv2undef_ad( &bv, ad, text );
678 int slap_bv2undef_ad(
680 AttributeDescription **ad,
683 AttributeDescription *desc;
685 assert( ad != NULL );
687 if( bv == NULL || bv->bv_len == 0 ) {
688 *text = "empty AttributeDescription";
689 return LDAP_UNDEFINED_TYPE;
692 /* make sure description is IA5 */
693 if( ad_keystring( bv ) ) {
694 *text = "AttributeDescription contains inappropriate characters";
695 return LDAP_UNDEFINED_TYPE;
698 for( desc = slap_schema.si_at_undefined->sat_ad; desc;
701 if( desc->ad_cname.bv_len == bv->bv_len &&
702 !strcasecmp( desc->ad_cname.bv_val, bv->bv_val ))
709 desc = ch_malloc(sizeof(AttributeDescription) + 1 +
712 desc->ad_flags = SLAP_DESC_NONE;
713 desc->ad_tags.bv_val = NULL;
714 desc->ad_tags.bv_len = 0;
716 desc->ad_cname.bv_len = bv->bv_len;
717 desc->ad_cname.bv_val = (char *)(desc+1);
718 strcpy(desc->ad_cname.bv_val, bv->bv_val);
720 /* canonical to upper case */
721 ldap_pvt_str2upper( desc->ad_cname.bv_val );
723 desc->ad_type = slap_schema.si_at_undefined;
724 desc->ad_next = desc->ad_type->sat_ad;
725 desc->ad_type->sat_ad = desc;
743 if( a == NULL ) return 0;
745 for ( ; a->an_name.bv_val; a++ ) {
746 if ( a->an_name.bv_len != s->bv_len) continue;
747 if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) {
756 * Convert a delimited string into a list of AttributeNames; add
757 * on to an existing list if it was given. If the string is not
758 * a valid attribute name, if a '-' is prepended it is skipped
759 * and the remaining name is tried again; if a '@' (or '+') is
760 * prepended, an objectclass name is searched instead; if a '!'
761 * is prepended, the objectclass name is negated.
763 * NOTE: currently, if a valid attribute name is not found, the
764 * same string is also checked as valid objectclass name; however,
765 * this behavior is deprecated.
768 str2anlist( AttributeName *an, char *in, const char *brkstr )
777 /* find last element in list */
778 for (i = 0; an && an[i].an_name.bv_val; i++);
780 /* protect the input string from strtok */
781 str = ch_strdup( in );
783 /* Count words in string */
785 for ( s = str; *s; s++ ) {
786 if ( strchr( brkstr, *s ) != NULL ) {
791 an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
792 BER_BVZERO( &an[i + j].an_name );
794 for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
796 s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
798 anew->an_desc = NULL;
800 anew->an_oc_exclude = 0;
801 ber_str2bv(s, 0, 1, &anew->an_name);
802 slap_bv2ad(&anew->an_name, &anew->an_desc, &text);
803 if ( !anew->an_desc ) {
804 switch( anew->an_name.bv_val[0] ) {
806 struct berval adname;
807 adname.bv_len = anew->an_name.bv_len - 1;
808 adname.bv_val = &anew->an_name.bv_val[1];
809 slap_bv2ad(&adname, &anew->an_desc, &text);
810 if ( !anew->an_desc ) {
816 case '+': /* (deprecated) */
818 struct berval ocname;
819 ocname.bv_len = anew->an_name.bv_len - 1;
820 ocname.bv_val = &anew->an_name.bv_val[1];
821 anew->an_oc = oc_bvfind( &ocname );
822 if ( !anew->an_oc ) {
826 if ( anew->an_name.bv_val[0] == '!' ) {
827 anew->an_oc_exclude = 1;
832 /* old (deprecated) way */
833 anew->an_oc = oc_bvfind( &anew->an_name );
834 if ( !anew->an_oc ) {
842 anew->an_name.bv_val = NULL;
847 for ( i = 0; an[i].an_name.bv_val; i++ ) {
848 free( an[i].an_name.bv_val );
852 * overwrites input string
860 char **anlist2charray_x( AttributeName *an, int dup, void *ctx )
866 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
868 attrs = (char **) slap_sl_malloc( (i + 1) * sizeof(char *), ctx );
869 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
871 attrs[i] = ch_strdup( an[i].an_name.bv_val );
873 attrs[i] = an[i].an_name.bv_val;
883 char **anlist2charray( AttributeName *an, int dup )
885 return anlist2charray_x( an, dup, NULL );
889 anlist2attrs( AttributeName * anlist )
896 attrs = anlist2charray( anlist, 1 );
898 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
899 if ( ( oc = anlist[i].an_oc ) ) {
900 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) ;
902 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) ;
913 attrs = (char **) ch_realloc( attrs, (i + k + 1) * sizeof( char * ));
915 for ( i = 0; anlist[i].an_name.bv_val; i++ ) {
916 if ( ( oc = anlist[i].an_oc ) ) {
917 for ( j = 0; oc->soc_required && oc->soc_required[j]; j++ ) {
918 attrs[n++] = ch_strdup(
919 oc->soc_required[j]->sat_cname.bv_val );
921 for ( j = 0; oc->soc_allowed && oc->soc_allowed[j]; j++ ) {
922 attrs[n++] = ch_strdup(
923 oc->soc_allowed[j]->sat_cname.bv_val );
932 while ( attrs && attrs[i] ) {
933 if ( *attrs[i] == '@' ) {
934 for ( j = i; attrs[j]; j++ ) {
937 attrs[j] = attrs[j+1];
944 for ( i = 0; attrs && attrs[i]; i++ ) {
946 while ( attrs && attrs[j] ) {
947 if ( !strcmp( attrs[i], attrs[j] )) {
948 for ( k = j; attrs && attrs[k]; k++ ) {
951 attrs[k] = attrs[k+1];
960 attrs = (char **) ch_realloc( attrs, (i+1) * sizeof( char * ));
967 file2anlist( AttributeName *an, const char *fname, const char *brkstr )
973 size_t lmax = LBUFSIZ;
975 fp = fopen( fname, "r" );
977 Debug( LDAP_DEBUG_ANY,
978 "get_attrs_from_file: failed to open attribute list file "
979 "\"%s\": %s\n", fname, strerror(errno), 0 );
983 lcur = line = (char *) ch_malloc( lmax );
985 Debug( LDAP_DEBUG_ANY,
986 "get_attrs_from_file: could not allocate memory\n",
992 while ( fgets( lcur, LBUFSIZ, fp ) != NULL ) {
993 if ( ( c = strchr( lcur, '\n' ) ) ) {
996 } else if ( *(c-1) == '\r' ) {
1003 line = (char *) ch_realloc( line, lmax );
1005 Debug( LDAP_DEBUG_ANY,
1006 "get_attrs_from_file: could not allocate memory\n",
1011 lcur = line + strlen( line );
1014 an = str2anlist( an, line, brkstr );
1025 /* Define an attribute option. */
1027 ad_define_option( const char *name, const char *fname, int lineno )
1030 unsigned int optlen;
1032 if ( options == &lang_option ) {
1041 if ( !DESC_CHAR( name[optlen] ) ) {
1042 Debug( LDAP_DEBUG_ANY,
1043 "%s: line %d: illegal option name \"%s\"\n",
1044 fname, lineno, name );
1047 } while ( name[++optlen] );
1049 options = ch_realloc( options,
1050 (option_count+1) * sizeof(Attr_option) );
1052 if ( strcasecmp( name, "binary" ) == 0
1053 || ad_find_option_definition( name, optlen ) ) {
1054 Debug( LDAP_DEBUG_ANY,
1055 "%s: line %d: option \"%s\" is already defined\n",
1056 fname, lineno, name );
1060 for ( i = option_count; i; --i ) {
1061 if ( strcasecmp( name, options[i-1].name.bv_val ) >= 0 )
1063 options[i] = options[i-1];
1066 options[i].name.bv_val = ch_strdup( name );
1067 options[i].name.bv_len = optlen;
1068 options[i].prefix = (name[optlen-1] == '-');
1070 if ( i != option_count &&
1071 options[i].prefix &&
1072 optlen < options[i+1].name.bv_len &&
1073 strncasecmp( name, options[i+1].name.bv_val, optlen ) == 0 ) {
1074 Debug( LDAP_DEBUG_ANY,
1075 "%s: line %d: option \"%s\" overrides previous option\n",
1076 fname, lineno, name );
1084 /* Find the definition of the option name or prefix matching the arguments */
1085 static Attr_option *
1086 ad_find_option_definition( const char *opt, int optlen )
1088 int top = 0, bot = option_count;
1089 while ( top < bot ) {
1090 int mid = (top + bot) / 2;
1091 int mlen = options[mid].name.bv_len;
1092 char *mname = options[mid].name.bv_val;
1094 if ( optlen < mlen ) {
1095 j = strncasecmp( opt, mname, optlen ) - 1;
1097 j = strncasecmp( opt, mname, mlen );
1098 if ( j==0 && (optlen==mlen || options[mid].prefix) )
1099 return &options[mid];
1109 MatchingRule *ad_mr(
1110 AttributeDescription *ad,
1113 switch( usage & SLAP_MR_TYPE_MASK ) {
1115 case SLAP_MR_EQUALITY:
1116 return ad->ad_type->sat_equality;
1118 case SLAP_MR_ORDERING:
1119 return ad->ad_type->sat_ordering;
1121 case SLAP_MR_SUBSTR:
1122 return ad->ad_type->sat_substr;
1126 assert( 0 /* ad_mr: bad usage */);