]> git.sur5r.net Git - openldap/blob - servers/slapd/at.c
Fix slapi_str2entry()/slapi_entry2str() allocation
[openldap] / servers / slapd / at.c
1 /* at.c - routines for dealing with attribute types */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/ctype.h>
22 #include <ac/errno.h>
23 #include <ac/socket.h>
24 #include <ac/string.h>
25 #include <ac/time.h>
26
27 #include "slap.h"
28
29
30 int is_at_syntax(
31         AttributeType *at,
32         const char *oid )
33 {
34         for( ; at != NULL; at = at->sat_sup ) {
35                 if( at->sat_syntax_oid ) {
36                         return ( strcmp( at->sat_syntax_oid, oid ) == 0 );
37                 }
38         }
39
40         return 0;
41 }
42
43 int is_at_subtype(
44         AttributeType *sub,
45         AttributeType *sup )
46 {
47         for( ; sub != NULL; sub = sub->sat_sup ) {
48                 if( sub == sup ) return 1;
49         }
50
51         return 0;
52 }
53
54 struct aindexrec {
55         struct berval   air_name;
56         AttributeType   *air_at;
57 };
58
59 static Avlnode  *attr_index = NULL;
60 static Avlnode  *attr_cache = NULL;
61 static LDAP_STAILQ_HEAD(ATList, slap_attribute_type) attr_list
62         = LDAP_STAILQ_HEAD_INITIALIZER(attr_list);
63
64 int at_oc_cache;
65
66 static int
67 attr_index_cmp(
68     const void  *v_air1,
69     const void  *v_air2 )
70 {
71         const struct aindexrec  *air1 = v_air1;
72         const struct aindexrec  *air2 = v_air2;
73         int i = air1->air_name.bv_len - air2->air_name.bv_len;
74         if (i) return i;
75         return (strcasecmp( air1->air_name.bv_val, air2->air_name.bv_val ));
76 }
77
78 static int
79 attr_index_name_cmp(
80     const void  *v_type,
81     const void  *v_air )
82 {
83     const struct berval    *type = v_type;
84     const struct aindexrec *air  = v_air;
85         int i = type->bv_len - air->air_name.bv_len;
86         if (i) return i;
87         return (strncasecmp( type->bv_val, air->air_name.bv_val, type->bv_len ));
88 }
89
90 AttributeType *
91 at_find( const char *name )
92 {
93         struct berval bv;
94
95         bv.bv_val = (char *)name;
96         bv.bv_len = strlen( name );
97
98         return at_bvfind( &bv );
99 }
100
101 AttributeType *
102 at_bvfind( struct berval *name )
103 {
104         struct aindexrec *air;
105
106         if ( attr_cache ) {
107                 air = avl_find( attr_cache, name, attr_index_name_cmp );
108                 if ( air ) return air->air_at;
109         }
110
111         air = avl_find( attr_index, name, attr_index_name_cmp );
112
113         if ( air && ( slapMode & SLAP_TOOL_MODE ) && at_oc_cache ) {
114                 avl_insert( &attr_cache, (caddr_t) air,
115                         attr_index_cmp, avl_dup_error );
116         }
117
118         return air != NULL ? air->air_at : NULL;
119 }
120
121 int
122 at_append_to_list(
123     AttributeType       *sat,
124     AttributeType       ***listp )
125 {
126         AttributeType   **list;
127         AttributeType   **list1;
128         int             size;
129
130         list = *listp;
131         if ( !list ) {
132                 size = 2;
133                 list = ch_calloc(size, sizeof(AttributeType *));
134                 if ( !list ) {
135                         return -1;
136                 }
137         } else {
138                 size = 0;
139                 list1 = *listp;
140                 while ( *list1 ) {
141                         size++;
142                         list1++;
143                 }
144                 size += 2;
145                 list1 = ch_realloc(list, size*sizeof(AttributeType *));
146                 if ( !list1 ) {
147                         return -1;
148                 }
149                 list = list1;
150         }
151         list[size-2] = sat;
152         list[size-1] = NULL;
153         *listp = list;
154         return 0;
155 }
156
157 int
158 at_delete_from_list(
159     int                 pos,
160     AttributeType       ***listp )
161 {
162         AttributeType   **list;
163         AttributeType   **list1;
164         int             i;
165         int             j;
166
167         if ( pos < 0 ) {
168                 return -2;
169         }
170         list = *listp;
171         for ( i=0; list[i]; i++ )
172                 ;
173         if ( pos >= i ) {
174                 return -2;
175         }
176         for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
177                 list[i] = list[j];
178         }
179         list[i] = NULL;
180         /* Tell the runtime this can be shrinked */
181         list1 = ch_realloc(list, (i+1)*sizeof(AttributeType **));
182         if ( !list1 ) {
183                 return -1;
184         }
185         *listp = list1;
186         return 0;
187 }
188
189 int
190 at_find_in_list(
191     AttributeType       *sat,
192     AttributeType       **list )
193 {
194         int     i;
195
196         if ( !list ) {
197                 return -1;
198         }
199         for ( i=0; list[i]; i++ ) {
200                 if ( sat == list[i] ) {
201                         return i;
202                 }
203         }
204         return -1;
205 }
206
207 void
208 at_destroy( void )
209 {
210         AttributeType *a;
211         avl_free(attr_index, ldap_memfree);
212
213         while( !LDAP_STAILQ_EMPTY(&attr_list) ) {
214                 a = LDAP_STAILQ_FIRST(&attr_list);
215                 LDAP_STAILQ_REMOVE_HEAD(&attr_list, sat_next);
216
217                 if ( a->sat_equality ) {
218                         MatchingRule    *mr;
219
220                         mr = mr_find( a->sat_equality->smr_oid );
221                         assert( mr != NULL );
222                         if ( mr != a->sat_equality ) {
223                                 ch_free( a->sat_equality );
224                                 a->sat_equality = NULL;
225                         }
226                 }
227
228                 assert( a->sat_syntax != NULL );
229                 if ( a->sat_syntax != NULL ) {
230                         Syntax          *syn;
231
232                         syn = syn_find( a->sat_syntax->ssyn_oid );
233                         assert( syn != NULL );
234                         if ( syn != a->sat_syntax ) {
235                                 ch_free( a->sat_syntax );
236                                 a->sat_syntax = NULL;
237                         }
238                 }
239
240                 if ( a->sat_oidmacro ) ldap_memfree( a->sat_oidmacro );
241                 if ( a->sat_subtypes ) ldap_memfree( a->sat_subtypes );
242                 ad_destroy(a->sat_ad);
243                 ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
244                 ldap_attributetype_free((LDAPAttributeType *)a);
245         }
246
247         if ( slap_schema.si_at_undefined ) {
248                 ad_destroy(slap_schema.si_at_undefined->sat_ad);
249         }
250 }
251
252 int
253 at_start( AttributeType **at )
254 {
255         assert( at != NULL );
256
257         *at = LDAP_STAILQ_FIRST(&attr_list);
258
259         return (*at != NULL);
260 }
261
262 int
263 at_next( AttributeType **at )
264 {
265         assert( at != NULL );
266
267 #if 1   /* pedantic check */
268         {
269                 AttributeType *tmp = NULL;
270
271                 LDAP_STAILQ_FOREACH(tmp,&attr_list,sat_next) {
272                         if ( tmp == *at ) {
273                                 break;
274                         }
275                 }
276
277                 assert( tmp != NULL );
278         }
279 #endif
280
281         *at = LDAP_STAILQ_NEXT(*at,sat_next);
282
283         return (*at != NULL);
284 }
285
286 /*
287  * check whether the two attributeTypes actually __are__ identical,
288  * or rather inconsistent
289  */
290 static int
291 at_check_dup(
292         AttributeType           *sat,
293         AttributeType           *new_sat )
294 {
295         if ( new_sat->sat_oid != NULL ) {
296                 if ( sat->sat_oid == NULL ) {
297                         return SLAP_SCHERR_ATTR_INCONSISTENT;
298                 }
299
300                 if ( strcmp( sat->sat_oid, new_sat->sat_oid ) != 0 ) {
301                         return SLAP_SCHERR_ATTR_INCONSISTENT;
302                 }
303
304         } else {
305                 if ( sat->sat_oid != NULL ) {
306                         return SLAP_SCHERR_ATTR_INCONSISTENT;
307                 }
308         }
309
310         if ( new_sat->sat_names ) {
311                 int     i;
312
313                 if ( sat->sat_names == NULL ) {
314                         return SLAP_SCHERR_ATTR_INCONSISTENT;
315                 }
316
317                 for ( i = 0; new_sat->sat_names[ i ]; i++ ) {
318                         if ( sat->sat_names[ i ] == NULL ) {
319                                 return SLAP_SCHERR_ATTR_INCONSISTENT;
320                         }
321                         
322                         if ( strcasecmp( sat->sat_names[ i ],
323                                         new_sat->sat_names[ i ] ) != 0 )
324                         {
325                                 return SLAP_SCHERR_ATTR_INCONSISTENT;
326                         }
327                 }
328         } else {
329                 if ( sat->sat_names != NULL ) {
330                         return SLAP_SCHERR_ATTR_INCONSISTENT;
331                 }
332         }
333
334         return SLAP_SCHERR_ATTR_DUP;
335 }
336
337
338 static int
339 at_insert(
340     AttributeType       *sat,
341     const char          **err )
342 {
343         struct aindexrec        *air;
344         char                    **names;
345
346
347         if ( sat->sat_oid ) {
348                 air = (struct aindexrec *)
349                         ch_calloc( 1, sizeof(struct aindexrec) );
350                 air->air_name.bv_val = sat->sat_oid;
351                 air->air_name.bv_len = strlen(sat->sat_oid);
352                 air->air_at = sat;
353                 if ( avl_insert( &attr_index, (caddr_t) air,
354                                  attr_index_cmp, avl_dup_error ) )
355                 {
356                         AttributeType   *old_sat;
357                         int             rc;
358
359                         *err = sat->sat_oid;
360
361                         old_sat = at_bvfind( &air->air_name );
362                         assert( old_sat != NULL );
363                         rc = at_check_dup( old_sat, sat );
364
365                         ldap_memfree( air );
366
367                         return rc;
368                 }
369                 /* FIX: temporal consistency check */
370                 at_bvfind( &air->air_name );
371         }
372
373         names = sat->sat_names;
374         if ( names ) {
375                 while ( *names ) {
376                         air = (struct aindexrec *)
377                                 ch_calloc( 1, sizeof(struct aindexrec) );
378                         air->air_name.bv_val = *names;
379                         air->air_name.bv_len = strlen(*names);
380                         air->air_at = sat;
381                         if ( avl_insert( &attr_index, (caddr_t) air,
382                                          attr_index_cmp, avl_dup_error ) )
383                         {
384                                 AttributeType   *old_sat;
385                                 int             rc;
386
387                                 *err = *names;
388
389                                 old_sat = at_bvfind( &air->air_name );
390                                 assert( old_sat != NULL );
391                                 rc = at_check_dup( old_sat, sat );
392
393                                 ldap_memfree(air);
394
395                                 return rc;
396                         }
397                         /* FIX: temporal consistency check */
398                         at_bvfind(&air->air_name);
399                         names++;
400                 }
401         }
402
403         LDAP_STAILQ_INSERT_TAIL( &attr_list, sat, sat_next );
404
405         return 0;
406 }
407
408 int
409 at_add(
410         LDAPAttributeType       *at,
411         int                     user,
412         AttributeType           **rsat,
413         const char              **err )
414 {
415         AttributeType   *sat;
416         MatchingRule    *mr;
417         Syntax          *syn;
418         int             i;
419         int             code;
420         char    *cname;
421         char    *oid;
422         char    *oidm = NULL;
423
424         if ( !OID_LEADCHAR( at->at_oid[0] )) {
425                 /* Expand OID macros */
426                 oid = oidm_find( at->at_oid );
427                 if ( !oid ) {
428                         *err = at->at_oid;
429                         return SLAP_SCHERR_OIDM;
430                 }
431                 if ( oid != at->at_oid ) {
432                         oidm = at->at_oid;
433                         at->at_oid = oid;
434                 }
435         }
436
437         if ( at->at_syntax_oid && !OID_LEADCHAR( at->at_syntax_oid[0] )) {
438                 /* Expand OID macros */
439                 oid = oidm_find( at->at_syntax_oid );
440                 if ( !oid ) {
441                         *err = at->at_syntax_oid;
442                         return SLAP_SCHERR_OIDM;
443                 }
444                 if ( oid != at->at_syntax_oid ) {
445                         ldap_memfree( at->at_syntax_oid );
446                         at->at_syntax_oid = oid;
447                 }
448         }
449
450         if ( at->at_names && at->at_names[0] ) {
451                 int i;
452
453                 for( i=0; at->at_names[i]; i++ ) {
454                         if( !slap_valid_descr( at->at_names[i] ) ) {
455                                 *err = at->at_names[i];
456                                 return SLAP_SCHERR_BAD_DESCR;
457                         }
458                 }
459
460                 cname = at->at_names[0];
461
462         } else if ( at->at_oid ) {
463                 cname = at->at_oid;
464
465         } else {
466                 *err = "";
467                 return SLAP_SCHERR_ATTR_INCOMPLETE;
468         }
469
470         *err = cname;
471
472         if ( !at->at_usage && at->at_no_user_mod ) {
473                 /* user attribute must be modifable */
474                 return SLAP_SCHERR_ATTR_BAD_USAGE;
475         }
476
477         if ( at->at_collective ) {
478                 if( at->at_usage ) {
479                         /* collective attributes cannot be operational */
480                         return SLAP_SCHERR_ATTR_BAD_USAGE;
481                 }
482
483                 if( at->at_single_value ) {
484                         /* collective attributes cannot be single-valued */
485                         return SLAP_SCHERR_ATTR_BAD_USAGE;
486                 }
487         }
488
489         sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
490         AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
491
492         sat->sat_cname.bv_val = cname;
493         sat->sat_cname.bv_len = strlen( cname );
494         sat->sat_oidmacro = oidm;
495         ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
496
497         if ( at->at_sup_oid ) {
498                 AttributeType *supsat = at_find(at->at_sup_oid);
499
500                 if ( supsat == NULL ) {
501                         *err = at->at_sup_oid;
502                         code = SLAP_SCHERR_ATTR_NOT_FOUND;
503                         goto error_return;
504                 }
505
506                 sat->sat_sup = supsat;
507
508                 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
509                         code = SLAP_SCHERR_OUTOFMEM;
510                         goto error_return;
511                 }
512
513                 if ( sat->sat_usage != supsat->sat_usage ) {
514                         /* subtypes must have same usage as their SUP */
515                         code = SLAP_SCHERR_ATTR_BAD_USAGE;
516                         goto error_return;
517                 }
518
519                 if ( supsat->sat_obsolete && !sat->sat_obsolete ) {
520                         /* subtypes must be obsolete if super is */
521                         code = SLAP_SCHERR_ATTR_BAD_SUP;
522                         goto error_return;
523                 }
524
525                 if ( sat->sat_flags & SLAP_AT_FINAL ) {
526                         /* cannot subtype a "final" attribute type */
527                         code = SLAP_SCHERR_ATTR_BAD_SUP;
528                         goto error_return;
529                 }
530         }
531
532         /*
533          * Inherit definitions from superiors.  We only check the
534          * direct superior since that one has already inherited from
535          * its own superiorss
536          */
537         if ( sat->sat_sup ) {
538                 sat->sat_syntax = sat->sat_sup->sat_syntax;
539                 sat->sat_equality = sat->sat_sup->sat_equality;
540                 sat->sat_approx = sat->sat_sup->sat_approx;
541                 sat->sat_ordering = sat->sat_sup->sat_ordering;
542                 sat->sat_substr = sat->sat_sup->sat_substr;
543         }
544
545         /*
546          * check for X-ORDERED attributes
547          */
548         if ( sat->sat_extensions ) {
549                 for (i=0; sat->sat_extensions[i]; i++) {
550                         if (!strcasecmp( sat->sat_extensions[i]->lsei_name,
551                                 "X-ORDERED" ) && sat->sat_extensions[i]->lsei_values ) {
552                                 if ( !strcasecmp( sat->sat_extensions[i]->lsei_values[0],
553                                         "VALUES" )) {
554                                         sat->sat_flags |= SLAP_AT_ORDERED_VAL;
555                                         break;
556                                 } else if ( !strcasecmp( sat->sat_extensions[i]->lsei_values[0],
557                                         "SIBLINGS" )) {
558                                         sat->sat_flags |= SLAP_AT_ORDERED_SIB;
559                                         break;
560                                 }
561                         }
562                 }
563         }
564
565         if ( !user )
566                 sat->sat_flags |= SLAP_AT_HARDCODE;
567
568         if ( at->at_syntax_oid ) {
569                 syn = syn_find(sat->sat_syntax_oid);
570                 if ( syn == NULL ) {
571                         *err = sat->sat_syntax_oid;
572                         code = SLAP_SCHERR_SYN_NOT_FOUND;
573                         goto error_return;
574                 }
575
576                 if( sat->sat_syntax != NULL && sat->sat_syntax != syn ) {
577                         code = SLAP_SCHERR_ATTR_BAD_SUP;
578                         goto error_return;
579                 }
580
581                 sat->sat_syntax = syn;
582
583         } else if ( sat->sat_syntax == NULL ) {
584                 code = SLAP_SCHERR_ATTR_INCOMPLETE;
585                 goto error_return;
586         }
587
588         if ( sat->sat_equality_oid ) {
589                 mr = mr_find(sat->sat_equality_oid);
590
591                 if( mr == NULL ) {
592                         *err = sat->sat_equality_oid;
593                         code = SLAP_SCHERR_MR_NOT_FOUND;
594                         goto error_return;
595                 }
596
597                 if(( mr->smr_usage & SLAP_MR_EQUALITY ) != SLAP_MR_EQUALITY ) {
598                         *err = sat->sat_equality_oid;
599                         code = SLAP_SCHERR_ATTR_BAD_MR;
600                         goto error_return;
601                 }
602
603                 if( sat->sat_syntax != mr->smr_syntax ) {
604                         if( mr->smr_compat_syntaxes == NULL ) {
605                                 *err = sat->sat_equality_oid;
606                                 code = SLAP_SCHERR_ATTR_BAD_MR;
607                                 goto error_return;
608                         }
609
610                         for(i=0; mr->smr_compat_syntaxes[i]; i++) {
611                                 if( sat->sat_syntax == mr->smr_compat_syntaxes[i] ) {
612                                         i = -1;
613                                         break;
614                                 }
615                         }
616
617                         if( i >= 0 ) {
618                                 *err = sat->sat_equality_oid;
619                                 code = SLAP_SCHERR_ATTR_BAD_MR;
620                                 goto error_return;
621                         }
622                 }
623
624                 sat->sat_equality = mr;
625                 sat->sat_approx = mr->smr_associated;
626         }
627
628         if ( sat->sat_ordering_oid ) {
629                 if( !sat->sat_equality ) {
630                         *err = sat->sat_ordering_oid;
631                         code = SLAP_SCHERR_ATTR_BAD_MR;
632                         goto error_return;
633                 }
634
635                 mr = mr_find(sat->sat_ordering_oid);
636
637                 if( mr == NULL ) {
638                         *err = sat->sat_ordering_oid;
639                         code = SLAP_SCHERR_MR_NOT_FOUND;
640                         goto error_return;
641                 }
642
643                 if(( mr->smr_usage & SLAP_MR_ORDERING ) != SLAP_MR_ORDERING ) {
644                         *err = sat->sat_ordering_oid;
645                         code = SLAP_SCHERR_ATTR_BAD_MR;
646                         goto error_return;
647                 }
648
649                 if( sat->sat_syntax != mr->smr_syntax ) {
650                         if( mr->smr_compat_syntaxes == NULL ) {
651                                 *err = sat->sat_ordering_oid;
652                                 code = SLAP_SCHERR_ATTR_BAD_MR;
653                                 goto error_return;
654                         }
655
656                         for(i=0; mr->smr_compat_syntaxes[i]; i++) {
657                                 if( sat->sat_syntax == mr->smr_compat_syntaxes[i] ) {
658                                         i = -1;
659                                         break;
660                                 }
661                         }
662
663                         if( i >= 0 ) {
664                                 *err = sat->sat_ordering_oid;
665                                 code = SLAP_SCHERR_ATTR_BAD_MR;
666                                 goto error_return;
667                         }
668                 }
669
670                 sat->sat_ordering = mr;
671         }
672
673         if ( sat->sat_substr_oid ) {
674                 if( !sat->sat_equality ) {
675                         *err = sat->sat_substr_oid;
676                         code = SLAP_SCHERR_ATTR_BAD_MR;
677                         goto error_return;
678                 }
679
680                 mr = mr_find(sat->sat_substr_oid);
681
682                 if( mr == NULL ) {
683                         *err = sat->sat_substr_oid;
684                         code = SLAP_SCHERR_MR_NOT_FOUND;
685                         goto error_return;
686                 }
687
688                 if(( mr->smr_usage & SLAP_MR_SUBSTR ) != SLAP_MR_SUBSTR ) {
689                         *err = sat->sat_substr_oid;
690                         code = SLAP_SCHERR_ATTR_BAD_MR;
691                         goto error_return;
692                 }
693
694                 /* due to funky LDAP builtin substring rules,
695                  * we check against the equality rule assertion
696                  * syntax and compat syntaxes instead of those
697                  * associated with the substrings rule.
698                  */
699                 if( sat->sat_syntax != sat->sat_equality->smr_syntax ) {
700                         if( sat->sat_equality->smr_compat_syntaxes == NULL ) {
701                                 *err = sat->sat_substr_oid;
702                                 code = SLAP_SCHERR_ATTR_BAD_MR;
703                                 goto error_return;
704                         }
705
706                         for(i=0; sat->sat_equality->smr_compat_syntaxes[i]; i++) {
707                                 if( sat->sat_syntax ==
708                                         sat->sat_equality->smr_compat_syntaxes[i] )
709                                 {
710                                         i = -1;
711                                         break;
712                                 }
713                         }
714
715                         if( i >= 0 ) {
716                                 *err = sat->sat_substr_oid;
717                                 code = SLAP_SCHERR_ATTR_BAD_MR;
718                                 goto error_return;
719                         }
720                 }
721
722                 sat->sat_substr = mr;
723         }
724
725         code = at_insert( sat, err );
726         if ( code != 0 ) {
727 error_return:;
728                 if ( sat ) {
729                         ldap_pvt_thread_mutex_destroy( &sat->sat_ad_mutex );
730                         ch_free( sat );
731                 }
732
733                 if ( oidm ) {
734                         SLAP_FREE( at->at_oid );
735                         at->at_oid = oidm;
736                 }
737
738         } else if ( rsat ) {
739                 *rsat = sat;
740         }
741
742         return code;
743 }
744
745 #ifdef LDAP_DEBUG
746 static int
747 at_index_printnode( void *v_air, void *ignore )
748 {
749         struct aindexrec *air = v_air;
750         printf("%s = %s\n",
751                 air->air_name.bv_val,
752                 ldap_attributetype2str(&air->air_at->sat_atype) );
753         return( 0 );
754 }
755
756 static void
757 at_index_print( void )
758 {
759         printf("Printing attribute type index:\n");
760         (void) avl_apply( attr_index, at_index_printnode, 0, -1, AVL_INORDER );
761 }
762 #endif
763
764 void
765 at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )
766 {
767         AttributeType *at;
768         int i, num;
769         struct berval bv, *bva = NULL, idx;
770         char ibuf[32];
771
772         if ( !start )
773                 start = LDAP_STAILQ_FIRST( &attr_list );
774
775         /* count the result size */
776         i = 0;
777         for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
778                 if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
779                 i++;
780                 if ( at == end ) break;
781         }
782         if (!i) return;
783
784         num = i;
785         bva = ch_malloc( (num+1) * sizeof(struct berval) );
786         BER_BVZERO( bva );
787         idx.bv_val = ibuf;
788         if ( sys ) {
789                 idx.bv_len = 0;
790                 ibuf[0] = '\0';
791         }
792         i = 0;
793         for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
794                 LDAPAttributeType lat, *latp;
795                 if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
796                 if ( at->sat_oidmacro ) {
797                         lat = at->sat_atype;
798                         lat.at_oid = at->sat_oidmacro;
799                         latp = &lat;
800                 } else {
801                         latp = &at->sat_atype;
802                 }
803                 if ( ldap_attributetype2bv( latp, &bv ) == NULL ) {
804                         ber_bvarray_free( bva );
805                 }
806                 if ( !sys ) {
807                         idx.bv_len = sprintf(idx.bv_val, "{%d}", i);
808                 }
809                 bva[i].bv_len = idx.bv_len + bv.bv_len;
810                 bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
811                 strcpy( bva[i].bv_val, ibuf );
812                 strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
813                 i++;
814                 bva[i].bv_val = NULL;
815                 ldap_memfree( bv.bv_val );
816                 if ( at == end ) break;
817         }
818         *res = bva;
819 }
820
821 int
822 at_schema_info( Entry *e )
823 {
824         AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
825         AttributeType   *at;
826         struct berval   val;
827         struct berval   nval;
828
829         LDAP_STAILQ_FOREACH(at,&attr_list,sat_next) {
830                 if( at->sat_flags & SLAP_AT_HIDE ) continue;
831
832                 if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
833                         return -1;
834                 }
835
836                 ber_str2bv( at->sat_oid, 0, 0, &nval );
837
838                 if( attr_merge_one( e, ad_attributeTypes, &val, &nval ) )
839                 {
840                         return -1;
841                 }
842                 ldap_memfree( val.bv_val );
843         }
844         return 0;
845 }