1 /* entry.c - routines for dealing with entries */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
33 #include <ac/socket.h>
34 #include <ac/string.h>
39 static char *ebuf; /* buf returned by entry2str */
40 static char *ecur; /* pointer to end of currently used ebuf */
41 static int emaxsize;/* max size of ebuf */
46 const Entry slap_entry_root = {
47 NOID, { 0, "" }, { 0, "" }, NULL, 0, { 0, "" }, NULL
51 * these mutexes must be used when calling the entry2str()
52 * routine since it returns a pointer to static data.
54 ldap_pvt_thread_mutex_t entry2str_mutex;
56 static const struct berval dn_bv = BER_BVC("dn");
61 * Allocate in chunks, minimum of 1000 at a time.
63 #define CHUNK_SIZE 1000
64 typedef struct slap_list {
65 struct slap_list *next;
67 static slap_list *entry_chunks;
68 static Entry *entry_list;
69 static ldap_pvt_thread_mutex_t entry_mutex;
71 int entry_destroy(void)
74 if ( ebuf ) free( ebuf );
79 for ( e=entry_chunks; e; e=entry_chunks ) {
80 entry_chunks = e->next;
84 ldap_pvt_thread_mutex_destroy( &entry_mutex );
85 ldap_pvt_thread_mutex_destroy( &entry2str_mutex );
86 return attr_destroy();
92 ldap_pvt_thread_mutex_init( &entry2str_mutex );
93 ldap_pvt_thread_mutex_init( &entry_mutex );
100 return str2entry2( s, 1 );
103 #define bvcasematch(bv1, bv2) (ber_bvstrcasecmp(bv1, bv2) == 0)
106 str2entry2( char *s, int checkvals )
110 struct berval *type, *vals, *nvals;
112 AttributeDescription *ad, *ad_prev;
117 Attribute ahead, *atail;
120 * LDIF is used as the string format.
121 * An entry looks like this:
124 * [<attr>:[:] <value>\n]
125 * [<tab><continuedvalue>\n]*
128 * If a double colon is used after a type, it means the
129 * following value is encoded as a base 64 string. This
130 * happens if the value contains a non-printing character
134 Debug( LDAP_DEBUG_TRACE, "=> str2entry: \"%s\"\n",
135 s ? s : "NULL", 0, 0 );
140 Debug( LDAP_DEBUG_ANY,
141 "<= str2entry NULL (entry allocation failed)\n",
146 /* initialize entry */
149 /* dn + attributes */
157 lines = ldif_countlines( s );
158 type = ch_calloc( 1, (lines+1)*3*sizeof(struct berval)+lines );
160 nvals = vals+lines+1;
161 freeval = (char *)(nvals+lines+1);
164 /* parse into individual values, record DN */
165 while ( (s = ldif_getline( &next )) != NULL ) {
167 if ( *s == '\n' || *s == '\0' ) {
172 Debug( LDAP_DEBUG_TRACE,
173 "<= str2entry ran past end of entry\n", 0, 0, 0 );
177 rc = ldif_parse_line2( s, type+i, vals+i, &freev );
180 Debug( LDAP_DEBUG_TRACE,
181 "<= str2entry NULL (parse_line)\n", 0, 0, 0 );
185 if ( bvcasematch( &type[i], &dn_bv ) ) {
186 if ( e->e_dn != NULL ) {
187 Debug( LDAP_DEBUG_ANY, "str2entry: "
188 "entry %ld has multiple DNs \"%s\" and \"%s\"\n",
189 (long) e->e_id, e->e_dn, vals[i].bv_val );
193 rc = dnPrettyNormal( NULL, &vals[i], &e->e_name, &e->e_nname, NULL );
194 if( rc != LDAP_SUCCESS ) {
195 Debug( LDAP_DEBUG_ANY, "str2entry: "
196 "entry %ld has invalid DN \"%s\"\n",
197 (long) e->e_id, vals[i].bv_val, 0 );
200 if ( freeval[i] ) free( vals[i].bv_val );
201 vals[i].bv_val = NULL;
208 /* check to make sure there was a dn: line */
209 if ( BER_BVISNULL( &e->e_name )) {
210 Debug( LDAP_DEBUG_ANY, "str2entry: entry %ld has no dn\n",
211 (long) e->e_id, 0, 0 );
215 /* Make sure all attributes with multiple values are contiguous */
221 for (i=0; i<lines; i++) {
222 for ( j=i+1; j<lines; j++ ) {
223 if ( bvcasematch( type+i, type+j )) {
224 /* out of order, move intervening attributes down */
228 for ( k=j; k>i; k-- ) {
231 freeval[k] = freeval[k-1];
244 for ( i=0; i<=lines; i++ ) {
246 if ( !ad || ( i<lines && !bvcasematch( type+i, &ad->ad_cname ))) {
248 rc = slap_bv2ad( type+i, &ad, &text );
250 if( rc != LDAP_SUCCESS ) {
251 Debug( slapMode & SLAP_TOOL_MODE
252 ? LDAP_DEBUG_ANY : LDAP_DEBUG_TRACE,
253 "<= str2entry: str2ad(%s): %s\n", type[i].bv_val, text, 0 );
254 if( slapMode & SLAP_TOOL_MODE ) {
258 rc = slap_bv2undef_ad( type+i, &ad, &text, 0 );
259 if( rc != LDAP_SUCCESS ) {
260 Debug( LDAP_DEBUG_ANY,
261 "<= str2entry: slap_str2undef_ad(%s): %s\n",
262 type[i].bv_val, text, 0 );
267 /* require ';binary' when appropriate (ITS#5071) */
268 if ( slap_syntax_is_binary( ad->ad_type->sat_syntax ) && !slap_ad_is_binary( ad ) ) {
269 Debug( LDAP_DEBUG_ANY,
270 "str2entry: attributeType %s #%d: "
271 "needs ';binary' transfer as per syntax %s\n",
272 ad->ad_cname.bv_val, 0,
273 ad->ad_type->sat_syntax->ssyn_oid );
278 if (( ad_prev && ad != ad_prev ) || ( i == lines )) {
280 /* FIXME: we only need this when migrating from an unsorted DB */
281 if ( atail != &ahead && atail->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
282 rc = slap_sort_vals( (Modifications *)atail, &text, &j, NULL );
283 if ( rc == LDAP_SUCCESS ) {
284 atail->a_flags |= SLAP_ATTR_SORTED_VALS;
285 } else if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
286 Debug( LDAP_DEBUG_ANY,
287 "str2entry: attributeType %s value #%d provided more than once\n",
288 atail->a_desc->ad_cname.bv_val, j, 0 );
292 atail->a_next = attr_alloc( NULL );
293 atail = atail->a_next;
295 atail->a_numvals = attr_cnt;
296 atail->a_desc = ad_prev;
297 atail->a_vals = ch_malloc( (attr_cnt + 1) * sizeof(struct berval));
298 if( ad_prev->ad_type->sat_equality &&
299 ad_prev->ad_type->sat_equality->smr_normalize )
300 atail->a_nvals = ch_malloc( (attr_cnt + 1) * sizeof(struct berval));
302 atail->a_nvals = NULL;
304 for ( j=0; j<attr_cnt; j++ ) {
306 atail->a_vals[j] = vals[k];
308 ber_dupbv( atail->a_vals+j, &vals[k] );
309 vals[k].bv_val = NULL;
310 if ( atail->a_nvals ) {
311 atail->a_nvals[j] = nvals[k];
312 nvals[k].bv_val = NULL;
316 BER_BVZERO( &atail->a_vals[j] );
317 if ( atail->a_nvals ) {
318 BER_BVZERO( &atail->a_nvals[j] );
320 atail->a_nvals = atail->a_vals;
323 if ( i == lines ) break;
326 if ( BER_BVISNULL( &vals[i] ) ) {
327 Debug( LDAP_DEBUG_ANY,
328 "str2entry: attributeType %s #%d: "
330 ad->ad_cname.bv_val, attr_cnt, 0 );
334 if( slapMode & SLAP_TOOL_MODE ) {
336 slap_syntax_validate_func *validate =
337 ad->ad_type->sat_syntax->ssyn_validate;
338 slap_syntax_transform_func *pretty =
339 ad->ad_type->sat_syntax->ssyn_pretty;
342 rc = ordered_value_pretty( ad,
343 &vals[i], &pval, NULL );
345 } else if ( validate ) {
347 * validate value per syntax
349 rc = ordered_value_validate( ad, &vals[i], LDAP_MOD_ADD );
352 Debug( LDAP_DEBUG_ANY,
353 "str2entry: attributeType %s #%d: "
354 "no validator for syntax %s\n",
355 ad->ad_cname.bv_val, attr_cnt,
356 ad->ad_type->sat_syntax->ssyn_oid );
361 Debug( LDAP_DEBUG_ANY,
362 "str2entry: invalid value "
363 "for attributeType %s #%d (syntax %s)\n",
364 ad->ad_cname.bv_val, attr_cnt,
365 ad->ad_type->sat_syntax->ssyn_oid );
370 if ( freeval[i] ) free( vals[i].bv_val );
376 if ( ad->ad_type->sat_equality &&
377 ad->ad_type->sat_equality->smr_normalize )
379 rc = ordered_value_normalize(
380 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
382 ad->ad_type->sat_equality,
383 &vals[i], &nvals[i], NULL );
386 Debug( LDAP_DEBUG_ANY,
387 "<= str2entry NULL (smr_normalize %s %d)\n", ad->ad_cname.bv_val, rc, 0 );
396 atail->a_next = NULL;
397 e->e_attrs = ahead.a_next;
399 Debug(LDAP_DEBUG_TRACE, "<= str2entry(%s) -> 0x%lx\n",
400 e->e_dn, (unsigned long) e, 0 );
404 for ( i=0; i<lines; i++ ) {
405 if ( freeval[i] ) free( vals[i].bv_val );
406 free( nvals[i].bv_val );
414 #define GRABSIZE BUFSIZ
416 #define MAKE_SPACE( n ) { \
417 while ( ecur + (n) > ebuf + emaxsize ) { \
419 offset = (int) (ecur - ebuf); \
420 ebuf = ch_realloc( ebuf, \
421 emaxsize + GRABSIZE ); \
422 emaxsize += GRABSIZE; \
423 ecur = ebuf + offset; \
440 * In string format, an entry looks like this:
442 * [<attr>: <value>\n]*
448 if ( e->e_dn != NULL ) {
450 tmplen = e->e_name.bv_len;
451 MAKE_SPACE( LDIF_SIZE_NEEDED( 2, tmplen ));
452 ldif_sput( &ecur, LDIF_PUT_VALUE, "dn", e->e_dn, tmplen );
455 /* put the attributes */
456 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
457 /* put "<type>:[:] <value>" line for each value */
458 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
460 tmplen = a->a_desc->ad_cname.bv_len;
461 MAKE_SPACE( LDIF_SIZE_NEEDED( tmplen, bv->bv_len ));
462 ldif_sput( &ecur, LDIF_PUT_VALUE,
463 a->a_desc->ad_cname.bv_val,
464 bv->bv_val, bv->bv_len );
475 entry_clean( Entry *e )
477 /* free an entry structure */
480 /* e_private must be freed by the caller */
481 assert( e->e_private == NULL );
486 if ( !BER_BVISNULL( &e->e_name ) ) {
487 free( e->e_name.bv_val );
488 BER_BVZERO( &e->e_name );
490 if ( !BER_BVISNULL( &e->e_nname ) ) {
491 free( e->e_nname.bv_val );
492 BER_BVZERO( &e->e_nname );
495 if ( !BER_BVISNULL( &e->e_bv ) ) {
496 free( e->e_bv.bv_val );
497 BER_BVZERO( &e->e_bv );
500 /* free attributes */
502 attrs_free( e->e_attrs );
510 entry_free( Entry *e )
514 ldap_pvt_thread_mutex_lock( &entry_mutex );
515 e->e_private = entry_list;
517 ldap_pvt_thread_mutex_unlock( &entry_mutex );
520 /* These parameters work well on AMD64 */
528 #define STRIDE_FACTOR (STRIDE*STRIPE)
531 entry_prealloc( int num )
533 Entry *e, **prev, *tmp;
539 #if STRIDE_FACTOR > 1
540 /* Round up to our stride factor */
541 num += STRIDE_FACTOR-1;
542 num /= STRIDE_FACTOR;
543 num *= STRIDE_FACTOR;
546 s = ch_calloc( 1, sizeof(slap_list) + num * sizeof(Entry));
547 s->next = entry_chunks;
551 for (i=0; i<STRIPE; i++) {
554 for (j=i; j<num; j+= STRIDE) {
556 prev = (Entry **)&e->e_private;
561 entry_list = (Entry *)(s+1);
571 ldap_pvt_thread_mutex_lock( &entry_mutex );
573 entry_prealloc( CHUNK_SIZE );
575 entry_list = e->e_private;
577 ldap_pvt_thread_mutex_unlock( &entry_mutex );
584 * These routines are used only by Backend.
586 * the Entry has three entry points (ways to find things):
588 * by entry e.g., if you already have an entry from the cache
589 * and want to delete it. (really by entry ptr)
590 * by dn e.g., when looking for the base object of a search
591 * by id e.g., for search candidates
593 * these correspond to three different avl trees that are maintained.
597 entry_cmp( Entry *e1, Entry *e2 )
599 return SLAP_PTRCMP( e1, e2 );
603 entry_dn_cmp( const void *v_e1, const void *v_e2 )
605 /* compare their normalized UPPERCASED dn's */
606 const Entry *e1 = v_e1, *e2 = v_e2;
608 return ber_bvcmp( &e1->e_nname, &e2->e_nname );
612 entry_id_cmp( const void *v_e1, const void *v_e2 )
614 const Entry *e1 = v_e1, *e2 = v_e2;
615 return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) );
618 /* This is like a ber_len */
619 #define entry_lenlen(l) (((l) < 0x80) ? 1 : ((l) < 0x100) ? 2 : \
620 ((l) < 0x10000) ? 3 : ((l) < 0x1000000) ? 4 : 5)
623 entry_putlen(unsigned char **buf, ber_len_t len)
625 ber_len_t lenlen = entry_lenlen(len);
628 **buf = (unsigned char) len;
631 **buf = 0x80 | ((unsigned char) lenlen - 1);
632 for (i=lenlen-1; i>0; i--) {
633 (*buf)[i] = (unsigned char) len;
641 entry_getlen(unsigned char **buf)
658 /* Count up the sizes of the components of an entry */
659 void entry_partsize(Entry *e, ber_len_t *plen,
660 int *pnattrs, int *pnvals, int norm)
662 ber_len_t len, dnlen, ndnlen;
663 int i, nat = 0, nval = 0;
666 dnlen = e->e_name.bv_len;
667 len = dnlen + 1; /* trailing NUL byte */
668 len += entry_lenlen(dnlen);
670 ndnlen = e->e_nname.bv_len;
672 len += entry_lenlen(ndnlen);
674 for (a=e->e_attrs; a; a=a->a_next) {
675 /* For AttributeDesc, we only store the attr name */
677 len += a->a_desc->ad_cname.bv_len+1;
678 len += entry_lenlen(a->a_desc->ad_cname.bv_len);
679 for (i=0; a->a_vals[i].bv_val; i++) {
681 len += a->a_vals[i].bv_len + 1;
682 len += entry_lenlen(a->a_vals[i].bv_len);
684 len += entry_lenlen(i);
685 nval++; /* empty berval at end */
686 if (norm && a->a_nvals != a->a_vals) {
687 for (i=0; a->a_nvals[i].bv_val; i++) {
689 len += a->a_nvals[i].bv_len + 1;
690 len += entry_lenlen(a->a_nvals[i].bv_len);
692 len += entry_lenlen(i); /* i nvals */
695 len += entry_lenlen(0); /* 0 nvals */
698 len += entry_lenlen(nat);
699 len += entry_lenlen(nval);
705 /* Add up the size of the entry for a flattened buffer */
706 ber_len_t entry_flatsize(Entry *e, int norm)
711 entry_partsize(e, &len, &nattrs, &nvals, norm);
712 len += sizeof(Entry) + (nattrs * sizeof(Attribute)) +
713 (nvals * sizeof(struct berval));
717 /* Flatten an Entry into a buffer. The buffer is filled with just the
718 * strings/bervals of all the entry components. Each field is preceded
719 * by its length, encoded the way ber_put_len works. Every field is NUL
720 * terminated. The entire buffer size is precomputed so that a single
721 * malloc can be performed. The entry size is also recorded,
722 * to aid in entry_decode.
724 int entry_encode(Entry *e, struct berval *bv)
726 ber_len_t len, dnlen, ndnlen;
727 int i, nattrs, nvals;
731 Debug( LDAP_DEBUG_TRACE, "=> entry_encode(0x%08lx): %s\n",
732 (long) e->e_id, e->e_dn, 0 );
733 dnlen = e->e_name.bv_len;
734 ndnlen = e->e_nname.bv_len;
736 entry_partsize( e, &len, &nattrs, &nvals, 1 );
739 bv->bv_val = ch_malloc(len);
740 ptr = (unsigned char *)bv->bv_val;
741 entry_putlen(&ptr, nattrs);
742 entry_putlen(&ptr, nvals);
743 entry_putlen(&ptr, dnlen);
744 AC_MEMCPY(ptr, e->e_dn, dnlen);
747 entry_putlen(&ptr, ndnlen);
748 AC_MEMCPY(ptr, e->e_ndn, ndnlen);
752 for (a=e->e_attrs; a; a=a->a_next) {
753 entry_putlen(&ptr, a->a_desc->ad_cname.bv_len);
754 AC_MEMCPY(ptr, a->a_desc->ad_cname.bv_val,
755 a->a_desc->ad_cname.bv_len);
756 ptr += a->a_desc->ad_cname.bv_len;
759 for (i=0; a->a_vals[i].bv_val; i++);
760 assert( i == a->a_numvals );
761 entry_putlen(&ptr, i);
762 for (i=0; a->a_vals[i].bv_val; i++) {
763 entry_putlen(&ptr, a->a_vals[i].bv_len);
764 AC_MEMCPY(ptr, a->a_vals[i].bv_val,
765 a->a_vals[i].bv_len);
766 ptr += a->a_vals[i].bv_len;
769 if (a->a_nvals != a->a_vals) {
770 entry_putlen(&ptr, i);
771 for (i=0; a->a_nvals[i].bv_val; i++) {
772 entry_putlen(&ptr, a->a_nvals[i].bv_len);
773 AC_MEMCPY(ptr, a->a_nvals[i].bv_val,
774 a->a_nvals[i].bv_len);
775 ptr += a->a_nvals[i].bv_len;
779 entry_putlen(&ptr, 0);
786 /* Retrieve an Entry that was stored using entry_encode above.
787 * First entry_header must be called to decode the size of the entry.
788 * Then a single block of memory must be malloc'd to accomodate the
789 * bervals and the bulk data. Next the bulk data is retrieved from
790 * the DB and parsed by entry_decode.
792 * Note: everything is stored in a single contiguous block, so
793 * you can not free individual attributes or names from this
794 * structure. Attempting to do so will likely corrupt memory.
796 int entry_header(EntryHeader *eh)
798 unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
800 eh->nattrs = entry_getlen(&ptr);
802 Debug( LDAP_DEBUG_ANY,
803 "entry_header: attribute count was zero\n", 0, 0, 0);
806 eh->nvals = entry_getlen(&ptr);
808 Debug( LDAP_DEBUG_ANY,
809 "entry_header: value count was zero\n", 0, 0, 0);
812 eh->data = (char *)ptr;
816 #ifdef SLAP_ZONE_ALLOC
817 int entry_decode(EntryHeader *eh, Entry **e, void *ctx)
819 int entry_decode(EntryHeader *eh, Entry **e)
822 int i, j, nattrs, nvals;
827 AttributeDescription *ad;
828 unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
834 x->e_attrs = attrs_alloc( nattrs );
835 ptr = (unsigned char *)eh->data;
836 i = entry_getlen(&ptr);
837 x->e_name.bv_val = (char *) ptr;
838 x->e_name.bv_len = i;
840 i = entry_getlen(&ptr);
841 x->e_nname.bv_val = (char *) ptr;
842 x->e_nname.bv_len = i;
844 Debug( LDAP_DEBUG_TRACE,
845 "entry_decode: \"%s\"\n",
850 bptr = (BerVarray)eh->bv.bv_val;
852 while ((i = entry_getlen(&ptr))) {
855 bv.bv_val = (char *) ptr;
857 rc = slap_bv2ad( &bv, &ad, &text );
859 if( rc != LDAP_SUCCESS ) {
860 Debug( LDAP_DEBUG_TRACE,
861 "<= entry_decode: str2ad(%s): %s\n", ptr, text, 0 );
862 rc = slap_bv2undef_ad( &bv, &ad, &text, 0 );
864 if( rc != LDAP_SUCCESS ) {
865 Debug( LDAP_DEBUG_ANY,
866 "<= entry_decode: slap_str2undef_ad(%s): %s\n",
873 a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
874 j = entry_getlen(&ptr);
879 i = entry_getlen(&ptr);
881 bptr->bv_val = (char *)ptr;
890 j = entry_getlen(&ptr);
894 i = entry_getlen(&ptr);
896 bptr->bv_val = (char *)ptr;
905 a->a_nvals = a->a_vals;
907 /* FIXME: This is redundant once a sorted entry is saved into the DB */
908 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
909 rc = slap_sort_vals( (Modifications *)a, &text, &j, NULL );
910 if ( rc == LDAP_SUCCESS ) {
911 a->a_flags |= SLAP_ATTR_SORTED_VALS;
912 } else if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
913 /* should never happen */
914 Debug( LDAP_DEBUG_ANY,
915 "entry_decode: attributeType %s value #%d provided more than once\n",
916 a->a_desc->ad_cname.bv_val, j, 0 );
926 Debug(LDAP_DEBUG_TRACE, "<= entry_decode(%s)\n",
932 Entry *entry_dup( Entry *e )
939 ber_dupbv( &ret->e_name, &e->e_name );
940 ber_dupbv( &ret->e_nname, &e->e_nname );
941 ret->e_attrs = attrs_dup( e->e_attrs );
942 ret->e_ocflags = e->e_ocflags;
948 /* Duplicates an entry using a single malloc. Saves CPU time, increases
949 * heap usage because a single large malloc is harder to satisfy than
950 * lots of small ones, and the freed space isn't as easily reusable.
952 * Probably not worth using this function.
954 Entry *entry_dup_bv( Entry *e )
961 Attribute *src, *dst;
965 entry_partsize(e, &len, &nattrs, &nvals, 1);
967 ret->e_attrs = attrs_alloc( nattrs );
968 ret->e_ocflags = e->e_ocflags;
969 ret->e_bv.bv_len = len + nvals * sizeof(struct berval);
970 ret->e_bv.bv_val = ch_malloc( ret->e_bv.bv_len );
972 bvl = (struct berval *)ret->e_bv.bv_val;
973 ptr = (char *)(bvl + nvals);
975 ret->e_name.bv_len = e->e_name.bv_len;
976 ret->e_name.bv_val = ptr;
977 AC_MEMCPY( ptr, e->e_name.bv_val, e->e_name.bv_len );
978 ptr += e->e_name.bv_len;
981 ret->e_nname.bv_len = e->e_nname.bv_len;
982 ret->e_nname.bv_val = ptr;
983 AC_MEMCPY( ptr, e->e_nname.bv_val, e->e_nname.bv_len );
984 ptr += e->e_name.bv_len;
988 for (src = e->e_attrs; src; src=src->a_next,dst=dst->a_next ) {
990 dst->a_desc = src->a_desc;
991 dst->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
993 dst->a_numvals = src->a_numvals;
994 for ( i=0; src->a_vals[i].bv_val; i++ ) {
995 bvl->bv_len = src->a_vals[i].bv_len;
997 AC_MEMCPY( ptr, src->a_vals[i].bv_val, bvl->bv_len );
1004 if ( src->a_vals != src->a_nvals ) {
1006 for ( i=0; src->a_nvals[i].bv_val; i++ ) {
1007 bvl->bv_len = src->a_nvals[i].bv_len;
1009 AC_MEMCPY( ptr, src->a_nvals[i].bv_val, bvl->bv_len );