]> git.sur5r.net Git - openldap/blob - servers/slapd/at.c
784f3974ca736e93ed49097e9952efbdfdebd43f
[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_subtypes) ldap_memfree(a->sat_subtypes);
218                 ad_destroy(a->sat_ad);
219                 ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
220                 ldap_attributetype_free((LDAPAttributeType *)a);
221         }
222
223         if ( slap_schema.si_at_undefined ) {
224                 ad_destroy(slap_schema.si_at_undefined->sat_ad);
225         }
226 }
227
228 int
229 at_start( AttributeType **at )
230 {
231         assert( at );
232
233         *at = LDAP_STAILQ_FIRST(&attr_list);
234
235         return (*at != NULL);
236 }
237
238 int
239 at_next( AttributeType **at )
240 {
241         assert( at );
242
243 #if 1   /* pedantic check */
244         {
245                 AttributeType *tmp = NULL;
246
247                 LDAP_STAILQ_FOREACH(tmp,&attr_list,sat_next) {
248                         if ( tmp == *at ) {
249                                 break;
250                         }
251                 }
252
253                 assert( tmp );
254         }
255 #endif
256
257         *at = LDAP_STAILQ_NEXT(*at,sat_next);
258
259         return (*at != NULL);
260 }
261
262 /*
263  * check whether the two attributeTypes actually __are__ identical,
264  * or rather inconsistent
265  */
266 static int
267 at_check_dup(
268         AttributeType           *sat,
269         AttributeType           *new_sat )
270 {
271         if ( new_sat->sat_oid != NULL ) {
272                 if ( sat->sat_oid == NULL ) {
273                         return SLAP_SCHERR_ATTR_INCONSISTENT;
274                 }
275
276                 if ( strcmp( sat->sat_oid, new_sat->sat_oid ) != 0 ) {
277                         return SLAP_SCHERR_ATTR_INCONSISTENT;
278                 }
279
280         } else {
281                 if ( sat->sat_oid != NULL ) {
282                         return SLAP_SCHERR_ATTR_INCONSISTENT;
283                 }
284         }
285
286         if ( new_sat->sat_names ) {
287                 int     i;
288
289                 if ( sat->sat_names == NULL ) {
290                         return SLAP_SCHERR_ATTR_INCONSISTENT;
291                 }
292
293                 for ( i = 0; new_sat->sat_names[ i ]; i++ ) {
294                         if ( sat->sat_names[ i ] == NULL ) {
295                                 return SLAP_SCHERR_ATTR_INCONSISTENT;
296                         }
297                         
298                         if ( strcasecmp( sat->sat_names[ i ],
299                                         new_sat->sat_names[ i ] ) != 0 )
300                         {
301                                 return SLAP_SCHERR_ATTR_INCONSISTENT;
302                         }
303                 }
304         } else {
305                 if ( sat->sat_names != NULL ) {
306                         return SLAP_SCHERR_ATTR_INCONSISTENT;
307                 }
308         }
309
310         return SLAP_SCHERR_ATTR_DUP;
311 }
312
313
314 static int
315 at_insert(
316     AttributeType       *sat,
317     const char          **err )
318 {
319         struct aindexrec        *air;
320         char                    **names;
321
322
323         if ( sat->sat_oid ) {
324                 air = (struct aindexrec *)
325                         ch_calloc( 1, sizeof(struct aindexrec) );
326                 air->air_name.bv_val = sat->sat_oid;
327                 air->air_name.bv_len = strlen(sat->sat_oid);
328                 air->air_at = sat;
329                 if ( avl_insert( &attr_index, (caddr_t) air,
330                                  attr_index_cmp, avl_dup_error ) )
331                 {
332                         AttributeType   *old_sat;
333                         int             rc;
334
335                         *err = sat->sat_oid;
336
337                         old_sat = at_bvfind( &air->air_name );
338                         assert( old_sat != NULL );
339                         rc = at_check_dup( old_sat, sat );
340
341                         ldap_memfree( air );
342
343                         return rc;
344                 }
345                 /* FIX: temporal consistency check */
346                 at_bvfind( &air->air_name );
347         }
348
349         names = sat->sat_names;
350         if ( names ) {
351                 while ( *names ) {
352                         air = (struct aindexrec *)
353                                 ch_calloc( 1, sizeof(struct aindexrec) );
354                         air->air_name.bv_val = *names;
355                         air->air_name.bv_len = strlen(*names);
356                         air->air_at = sat;
357                         if ( avl_insert( &attr_index, (caddr_t) air,
358                                          attr_index_cmp, avl_dup_error ) )
359                         {
360                                 AttributeType   *old_sat;
361                                 int             rc;
362
363                                 *err = *names;
364
365                                 old_sat = at_bvfind( &air->air_name );
366                                 assert( old_sat != NULL );
367                                 rc = at_check_dup( old_sat, sat );
368
369                                 ldap_memfree(air);
370
371                                 return rc;
372                         }
373                         /* FIX: temporal consistency check */
374                         at_bvfind(&air->air_name);
375                         names++;
376                 }
377         }
378
379         LDAP_STAILQ_INSERT_TAIL( &attr_list, sat, sat_next );
380
381         return 0;
382 }
383
384 int
385 at_add(
386     LDAPAttributeType   *at,
387         int                             user,
388         AttributeType   **rsat,
389     const char          **err )
390 {
391         AttributeType   *sat;
392         MatchingRule    *mr;
393         Syntax          *syn;
394         int             i;
395         int             code;
396         char    *cname;
397         char    *oid;
398         char    *oidm = NULL;
399
400         if ( !OID_LEADCHAR( at->at_oid[0] )) {
401                 /* Expand OID macros */
402                 oid = oidm_find( at->at_oid );
403                 if ( !oid ) {
404                         *err = at->at_oid;
405                         return SLAP_SCHERR_OIDM;
406                 }
407                 if ( oid != at->at_oid ) {
408                         oidm = at->at_oid;
409                         at->at_oid = oid;
410                 }
411         }
412
413         if ( at->at_syntax_oid && !OID_LEADCHAR( at->at_syntax_oid[0] )) {
414                 /* Expand OID macros */
415                 oid = oidm_find( at->at_syntax_oid );
416                 if ( !oid ) {
417                         *err = at->at_syntax_oid;
418                         return SLAP_SCHERR_OIDM;
419                 }
420                 if ( oid != at->at_syntax_oid ) {
421                         ldap_memfree( at->at_syntax_oid );
422                         at->at_syntax_oid = oid;
423                 }
424         }
425
426         if ( at->at_names && at->at_names[0] ) {
427                 int i;
428
429                 for( i=0; at->at_names[i]; i++ ) {
430                         if( !slap_valid_descr( at->at_names[i] ) ) {
431                                 *err = at->at_names[i];
432                                 return SLAP_SCHERR_BAD_DESCR;
433                         }
434                 }
435
436                 cname = at->at_names[0];
437
438         } else if ( at->at_oid ) {
439                 cname = at->at_oid;
440
441         } else {
442                 *err = "";
443                 return SLAP_SCHERR_ATTR_INCOMPLETE;
444         }
445
446         *err = cname;
447
448         if ( !at->at_usage && at->at_no_user_mod ) {
449                 /* user attribute must be modifable */
450                 return SLAP_SCHERR_ATTR_BAD_USAGE;
451         }
452
453         if ( at->at_collective ) {
454                 if( at->at_usage ) {
455                         /* collective attributes cannot be operational */
456                         return SLAP_SCHERR_ATTR_BAD_USAGE;
457                 }
458
459                 if( at->at_single_value ) {
460                         /* collective attributes cannot be single-valued */
461                         return SLAP_SCHERR_ATTR_BAD_USAGE;
462                 }
463         }
464
465         sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
466         AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
467
468         sat->sat_cname.bv_val = cname;
469         sat->sat_cname.bv_len = strlen( cname );
470         sat->sat_oidmacro = oidm;
471         ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
472
473         if ( at->at_sup_oid ) {
474                 AttributeType *supsat = at_find(at->at_sup_oid);
475
476                 if ( supsat == NULL ) {
477                         *err = at->at_sup_oid;
478                         return SLAP_SCHERR_ATTR_NOT_FOUND;
479                 }
480
481                 sat->sat_sup = supsat;
482
483                 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
484                         return SLAP_SCHERR_OUTOFMEM;
485                 }
486
487                 if ( sat->sat_usage != supsat->sat_usage ) {
488                         /* subtypes must have same usage as their SUP */
489                         return SLAP_SCHERR_ATTR_BAD_USAGE;
490                 }
491
492                 if ( supsat->sat_obsolete && !sat->sat_obsolete ) {
493                         /* subtypes must be obsolete if super is */
494                         return SLAP_SCHERR_ATTR_BAD_SUP;
495                 }
496
497                 if ( sat->sat_flags & SLAP_AT_FINAL ) {
498                         /* cannot subtype a "final" attribute type */
499                         return SLAP_SCHERR_ATTR_BAD_SUP;
500                 }
501         }
502
503         /*
504          * Inherit definitions from superiors.  We only check the
505          * direct superior since that one has already inherited from
506          * its own superiorss
507          */
508         if ( sat->sat_sup ) {
509                 sat->sat_syntax = sat->sat_sup->sat_syntax;
510                 sat->sat_equality = sat->sat_sup->sat_equality;
511                 sat->sat_approx = sat->sat_sup->sat_approx;
512                 sat->sat_ordering = sat->sat_sup->sat_ordering;
513                 sat->sat_substr = sat->sat_sup->sat_substr;
514         }
515
516         /*
517          * check for X-ORDERED attributes
518          */
519         if ( sat->sat_extensions ) {
520                 for (i=0; sat->sat_extensions[i]; i++) {
521                         if (!strcasecmp( sat->sat_extensions[i]->lsei_name,
522                                 "X-ORDERED" )) {
523                                 sat->sat_flags |= SLAP_AT_ORDERED;
524                                 break;
525                         }
526                 }
527         }
528
529         if ( !user )
530                 sat->sat_flags |= SLAP_AT_HARDCODE;
531
532         if ( at->at_syntax_oid ) {
533                 syn = syn_find(sat->sat_syntax_oid);
534                 if ( syn == NULL ) {
535                         *err = sat->sat_syntax_oid;
536                         return SLAP_SCHERR_SYN_NOT_FOUND;
537                 }
538
539                 if( sat->sat_syntax != NULL && sat->sat_syntax != syn ) {
540                         return SLAP_SCHERR_ATTR_BAD_SUP;
541                 }
542
543                 sat->sat_syntax = syn;
544
545         } else if ( sat->sat_syntax == NULL ) {
546                 return SLAP_SCHERR_ATTR_INCOMPLETE;
547         }
548
549         if ( sat->sat_equality_oid ) {
550                 mr = mr_find(sat->sat_equality_oid);
551
552                 if( mr == NULL ) {
553                         *err = sat->sat_equality_oid;
554                         return SLAP_SCHERR_MR_NOT_FOUND;
555                 }
556
557                 if(( mr->smr_usage & SLAP_MR_EQUALITY ) != SLAP_MR_EQUALITY ) {
558                         *err = sat->sat_equality_oid;
559                         return SLAP_SCHERR_ATTR_BAD_MR;
560                 }
561
562                 if( sat->sat_syntax != mr->smr_syntax ) {
563                         if( mr->smr_compat_syntaxes == NULL ) {
564                                 *err = sat->sat_equality_oid;
565                                 return SLAP_SCHERR_ATTR_BAD_MR;
566                         }
567
568                         for(i=0; mr->smr_compat_syntaxes[i]; i++) {
569                                 if( sat->sat_syntax == mr->smr_compat_syntaxes[i] ) {
570                                         i = -1;
571                                         break;
572                                 }
573                         }
574
575                         if( i >= 0 ) {
576                                 *err = sat->sat_equality_oid;
577                                 return SLAP_SCHERR_ATTR_BAD_MR;
578                         }
579                 }
580
581                 sat->sat_equality = mr;
582                 sat->sat_approx = mr->smr_associated;
583         }
584
585         if ( sat->sat_ordering_oid ) {
586                 if( !sat->sat_equality ) {
587                         *err = sat->sat_ordering_oid;
588                         return SLAP_SCHERR_ATTR_BAD_MR;
589                 }
590
591                 mr = mr_find(sat->sat_ordering_oid);
592
593                 if( mr == NULL ) {
594                         *err = sat->sat_ordering_oid;
595                         return SLAP_SCHERR_MR_NOT_FOUND;
596                 }
597
598                 if(( mr->smr_usage & SLAP_MR_ORDERING ) != SLAP_MR_ORDERING ) {
599                         *err = sat->sat_ordering_oid;
600                         return SLAP_SCHERR_ATTR_BAD_MR;
601                 }
602
603                 if( sat->sat_syntax != mr->smr_syntax ) {
604                         if( mr->smr_compat_syntaxes == NULL ) {
605                                 *err = sat->sat_ordering_oid;
606                                 return SLAP_SCHERR_ATTR_BAD_MR;
607                         }
608
609                         for(i=0; mr->smr_compat_syntaxes[i]; i++) {
610                                 if( sat->sat_syntax == mr->smr_compat_syntaxes[i] ) {
611                                         i = -1;
612                                         break;
613                                 }
614                         }
615
616                         if( i >= 0 ) {
617                                 *err = sat->sat_ordering_oid;
618                                 return SLAP_SCHERR_ATTR_BAD_MR;
619                         }
620                 }
621
622                 sat->sat_ordering = mr;
623         }
624
625         if ( sat->sat_substr_oid ) {
626                 if( !sat->sat_equality ) {
627                         *err = sat->sat_substr_oid;
628                         return SLAP_SCHERR_ATTR_BAD_MR;
629                 }
630
631                 mr = mr_find(sat->sat_substr_oid);
632
633                 if( mr == NULL ) {
634                         *err = sat->sat_substr_oid;
635                         return SLAP_SCHERR_MR_NOT_FOUND;
636                 }
637
638                 if(( mr->smr_usage & SLAP_MR_SUBSTR ) != SLAP_MR_SUBSTR ) {
639                         *err = sat->sat_substr_oid;
640                         return SLAP_SCHERR_ATTR_BAD_MR;
641                 }
642
643                 /* due to funky LDAP builtin substring rules,
644                  * we check against the equality rule assertion
645                  * syntax and compat syntaxes instead of those
646                  * associated with the substrings rule.
647                  */
648                 if( sat->sat_syntax != sat->sat_equality->smr_syntax ) {
649                         if( sat->sat_equality->smr_compat_syntaxes == NULL ) {
650                                 *err = sat->sat_substr_oid;
651                                 return SLAP_SCHERR_ATTR_BAD_MR;
652                         }
653
654                         for(i=0; sat->sat_equality->smr_compat_syntaxes[i]; i++) {
655                                 if( sat->sat_syntax ==
656                                         sat->sat_equality->smr_compat_syntaxes[i] )
657                                 {
658                                         i = -1;
659                                         break;
660                                 }
661                         }
662
663                         if( i >= 0 ) {
664                                 *err = sat->sat_substr_oid;
665                                 return SLAP_SCHERR_ATTR_BAD_MR;
666                         }
667                 }
668
669                 sat->sat_substr = mr;
670         }
671
672         code = at_insert( sat, err );
673         if ( code == 0 && rsat )
674                 *rsat = sat;
675         return code;
676 }
677
678 #ifdef LDAP_DEBUG
679 static int
680 at_index_printnode( void *v_air, void *ignore )
681 {
682         struct aindexrec *air = v_air;
683         printf("%s = %s\n",
684                 air->air_name.bv_val,
685                 ldap_attributetype2str(&air->air_at->sat_atype) );
686         return( 0 );
687 }
688
689 static void
690 at_index_print( void )
691 {
692         printf("Printing attribute type index:\n");
693         (void) avl_apply( attr_index, at_index_printnode, 0, -1, AVL_INORDER );
694 }
695 #endif
696
697 void
698 at_unparse( BerVarray *res, AttributeType *start, AttributeType *end, int sys )
699 {
700         AttributeType *at;
701         int i, num;
702         struct berval bv, *bva = NULL, idx;
703         char ibuf[32];
704
705         if ( !start )
706                 start = LDAP_STAILQ_FIRST( &attr_list );
707
708         /* count the result size */
709         i = 0;
710         for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
711                 if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
712                 i++;
713                 if ( at == end ) break;
714         }
715         if (!i) return;
716
717         num = i;
718         bva = ch_malloc( (num+1) * sizeof(struct berval) );
719         BER_BVZERO( bva );
720         idx.bv_val = ibuf;
721         if ( sys ) {
722                 idx.bv_len = 0;
723                 ibuf[0] = '\0';
724         }
725         i = 0;
726         for ( at=start; at; at=LDAP_STAILQ_NEXT(at, sat_next)) {
727                 LDAPAttributeType lat, *latp;
728                 if ( sys && !(at->sat_flags & SLAP_AT_HARDCODE)) continue;
729                 if ( at->sat_oidmacro ) {
730                         lat = at->sat_atype;
731                         lat.at_oid = at->sat_oidmacro;
732                         latp = &lat;
733                 } else {
734                         latp = &at->sat_atype;
735                 }
736                 if ( ldap_attributetype2bv( latp, &bv ) == NULL ) {
737                         ber_bvarray_free( bva );
738                 }
739                 if ( !sys ) {
740                         idx.bv_len = sprintf(idx.bv_val, "{%d}", i);
741                 }
742                 bva[i].bv_len = idx.bv_len + bv.bv_len;
743                 bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
744                 strcpy( bva[i].bv_val, ibuf );
745                 strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
746                 i++;
747                 bva[i].bv_val = NULL;
748                 ldap_memfree( bv.bv_val );
749                 if ( at == end ) break;
750         }
751         *res = bva;
752 }
753
754 int
755 at_schema_info( Entry *e )
756 {
757         AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
758         AttributeType   *at;
759         struct berval   val;
760         struct berval   nval;
761
762         LDAP_STAILQ_FOREACH(at,&attr_list,sat_next) {
763                 if( at->sat_flags & SLAP_AT_HIDE ) continue;
764
765                 if ( ldap_attributetype2bv( &at->sat_atype, &val ) == NULL ) {
766                         return -1;
767                 }
768
769                 ber_str2bv( at->sat_oid, 0, 0, &nval );
770
771                 if( attr_merge_one( e, ad_attributeTypes, &val, &nval ) )
772                 {
773                         return -1;
774                 }
775                 ldap_memfree( val.bv_val );
776         }
777         return 0;
778 }