1 /* entry.c - routines for dealing with entries */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2015 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];
245 for ( i=0; i<=lines; i++ ) {
247 if ( !ad || ( i<lines && !bvcasematch( type+i, &ad->ad_cname ))) {
249 rc = slap_bv2ad( type+i, &ad, &text );
251 if( rc != LDAP_SUCCESS ) {
252 int wtool = ( slapMode & (SLAP_TOOL_MODE|SLAP_TOOL_READONLY) ) == SLAP_TOOL_MODE;
253 Debug( wtool ? LDAP_DEBUG_ANY : LDAP_DEBUG_TRACE,
254 "<= str2entry: str2ad(%s): %s\n", type[i].bv_val, text, 0 );
259 rc = slap_bv2undef_ad( type+i, &ad, &text, 0 );
260 if( rc != LDAP_SUCCESS ) {
261 Debug( LDAP_DEBUG_ANY,
262 "<= str2entry: slap_str2undef_ad(%s): %s\n",
263 type[i].bv_val, text, 0 );
268 /* require ';binary' when appropriate (ITS#5071) */
269 if ( slap_syntax_is_binary( ad->ad_type->sat_syntax ) && !slap_ad_is_binary( ad ) ) {
270 Debug( LDAP_DEBUG_ANY,
271 "str2entry: attributeType %s #%d: "
272 "needs ';binary' transfer as per syntax %s\n",
273 ad->ad_cname.bv_val, 0,
274 ad->ad_type->sat_syntax->ssyn_oid );
279 if (( ad_prev && ad != ad_prev ) || ( i == lines )) {
281 atail->a_next = attr_alloc( NULL );
282 atail = atail->a_next;
284 atail->a_numvals = attr_cnt;
285 atail->a_desc = ad_prev;
286 atail->a_vals = ch_malloc( (attr_cnt + 1) * sizeof(struct berval));
287 if( ad_prev->ad_type->sat_equality &&
288 ad_prev->ad_type->sat_equality->smr_normalize )
289 atail->a_nvals = ch_malloc( (attr_cnt + 1) * sizeof(struct berval));
291 atail->a_nvals = NULL;
293 for ( j=0; j<attr_cnt; j++ ) {
295 atail->a_vals[j] = vals[k];
297 ber_dupbv( atail->a_vals+j, &vals[k] );
298 vals[k].bv_val = NULL;
299 if ( atail->a_nvals ) {
300 atail->a_nvals[j] = nvals[k];
301 nvals[k].bv_val = NULL;
305 BER_BVZERO( &atail->a_vals[j] );
306 if ( atail->a_nvals ) {
307 BER_BVZERO( &atail->a_nvals[j] );
309 atail->a_nvals = atail->a_vals;
312 /* FIXME: we only need this when migrating from an unsorted DB */
313 if ( atail->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
314 rc = slap_sort_vals( (Modifications *)atail, &text, &j, NULL );
315 if ( rc == LDAP_SUCCESS ) {
316 atail->a_flags |= SLAP_ATTR_SORTED_VALS;
317 } else if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
318 Debug( LDAP_DEBUG_ANY,
319 "str2entry: attributeType %s value #%d provided more than once\n",
320 atail->a_desc->ad_cname.bv_val, j, 0 );
324 if ( i == lines ) break;
327 if ( BER_BVISNULL( &vals[i] ) ) {
328 Debug( LDAP_DEBUG_ANY,
329 "str2entry: attributeType %s #%d: "
331 ad->ad_cname.bv_val, attr_cnt, 0 );
335 if ( ad->ad_type->sat_equality &&
336 ad->ad_type->sat_equality->smr_normalize )
338 rc = ordered_value_normalize(
339 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
341 ad->ad_type->sat_equality,
342 &vals[i], &nvals[i], NULL );
345 Debug( LDAP_DEBUG_ANY,
346 "<= str2entry NULL (smr_normalize %s %d)\n", ad->ad_cname.bv_val, rc, 0 );
356 atail->a_next = NULL;
357 e->e_attrs = ahead.a_next;
359 Debug(LDAP_DEBUG_TRACE, "<= str2entry(%s) -> 0x%lx\n",
360 e->e_dn, (unsigned long) e, 0 );
364 for ( i=0; i<lines; i++ ) {
365 if ( freeval[i] ) free( vals[i].bv_val );
366 free( nvals[i].bv_val );
374 #define GRABSIZE BUFSIZ
376 #define MAKE_SPACE( n ) { \
377 while ( ecur + (n) > ebuf + emaxsize ) { \
379 offset = (int) (ecur - ebuf); \
380 ebuf = ch_realloc( ebuf, \
381 emaxsize + GRABSIZE ); \
382 emaxsize += GRABSIZE; \
383 ecur = ebuf + offset; \
387 /* NOTE: only preserved for binary compatibility */
393 return entry2str_wrap( e, len, LDIF_LINE_WIDTH );
410 * In string format, an entry looks like this:
412 * [<attr>: <value>\n]*
418 if ( e->e_dn != NULL ) {
420 tmplen = e->e_name.bv_len;
421 MAKE_SPACE( LDIF_SIZE_NEEDED( 2, tmplen ));
422 ldif_sput_wrap( &ecur, LDIF_PUT_VALUE, "dn", e->e_dn, tmplen, wrap );
425 /* put the attributes */
426 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
427 /* put "<type>:[:] <value>" line for each value */
428 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
430 tmplen = a->a_desc->ad_cname.bv_len;
431 MAKE_SPACE( LDIF_SIZE_NEEDED( tmplen, bv->bv_len ));
432 ldif_sput_wrap( &ecur, LDIF_PUT_VALUE,
433 a->a_desc->ad_cname.bv_val,
434 bv->bv_val, bv->bv_len, wrap );
445 entry_clean( Entry *e )
447 /* free an entry structure */
450 /* e_private must be freed by the caller */
451 assert( e->e_private == NULL );
456 if ( !BER_BVISNULL( &e->e_name ) ) {
457 free( e->e_name.bv_val );
458 BER_BVZERO( &e->e_name );
460 if ( !BER_BVISNULL( &e->e_nname ) ) {
461 free( e->e_nname.bv_val );
462 BER_BVZERO( &e->e_nname );
465 if ( !BER_BVISNULL( &e->e_bv ) ) {
466 free( e->e_bv.bv_val );
467 BER_BVZERO( &e->e_bv );
470 /* free attributes */
472 attrs_free( e->e_attrs );
480 entry_free( Entry *e )
484 ldap_pvt_thread_mutex_lock( &entry_mutex );
485 e->e_private = entry_list;
487 ldap_pvt_thread_mutex_unlock( &entry_mutex );
490 /* These parameters work well on AMD64 */
498 #define STRIDE_FACTOR (STRIDE*STRIPE)
501 entry_prealloc( int num )
503 Entry *e, **prev, *tmp;
509 #if STRIDE_FACTOR > 1
510 /* Round up to our stride factor */
511 num += STRIDE_FACTOR-1;
512 num /= STRIDE_FACTOR;
513 num *= STRIDE_FACTOR;
516 s = ch_calloc( 1, sizeof(slap_list) + num * sizeof(Entry));
517 s->next = entry_chunks;
521 for (i=0; i<STRIPE; i++) {
524 for (j=i; j<num; j+= STRIDE) {
526 prev = (Entry **)&e->e_private;
531 entry_list = (Entry *)(s+1);
541 ldap_pvt_thread_mutex_lock( &entry_mutex );
543 entry_prealloc( CHUNK_SIZE );
545 entry_list = e->e_private;
547 ldap_pvt_thread_mutex_unlock( &entry_mutex );
554 * These routines are used only by Backend.
556 * the Entry has three entry points (ways to find things):
558 * by entry e.g., if you already have an entry from the cache
559 * and want to delete it. (really by entry ptr)
560 * by dn e.g., when looking for the base object of a search
561 * by id e.g., for search candidates
563 * these correspond to three different avl trees that are maintained.
567 entry_cmp( Entry *e1, Entry *e2 )
569 return SLAP_PTRCMP( e1, e2 );
573 entry_dn_cmp( const void *v_e1, const void *v_e2 )
575 /* compare their normalized UPPERCASED dn's */
576 const Entry *e1 = v_e1, *e2 = v_e2;
578 return ber_bvcmp( &e1->e_nname, &e2->e_nname );
582 entry_id_cmp( const void *v_e1, const void *v_e2 )
584 const Entry *e1 = v_e1, *e2 = v_e2;
585 return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) );
588 /* This is like a ber_len */
589 #define entry_lenlen(l) (((l) < 0x80) ? 1 : ((l) < 0x100) ? 2 : \
590 ((l) < 0x10000) ? 3 : ((l) < 0x1000000) ? 4 : 5)
593 entry_putlen(unsigned char **buf, ber_len_t len)
595 ber_len_t lenlen = entry_lenlen(len);
598 **buf = (unsigned char) len;
601 **buf = 0x80 | ((unsigned char) lenlen - 1);
602 for (i=lenlen-1; i>0; i--) {
603 (*buf)[i] = (unsigned char) len;
611 entry_getlen(unsigned char **buf)
628 /* Count up the sizes of the components of an entry */
629 void entry_partsize(Entry *e, ber_len_t *plen,
630 int *pnattrs, int *pnvals, int norm)
632 ber_len_t len, dnlen, ndnlen;
633 int i, nat = 0, nval = 0;
636 dnlen = e->e_name.bv_len;
637 len = dnlen + 1; /* trailing NUL byte */
638 len += entry_lenlen(dnlen);
640 ndnlen = e->e_nname.bv_len;
642 len += entry_lenlen(ndnlen);
644 for (a=e->e_attrs; a; a=a->a_next) {
645 /* For AttributeDesc, we only store the attr name */
647 len += a->a_desc->ad_cname.bv_len+1;
648 len += entry_lenlen(a->a_desc->ad_cname.bv_len);
649 for (i=0; a->a_vals[i].bv_val; i++) {
651 len += a->a_vals[i].bv_len + 1;
652 len += entry_lenlen(a->a_vals[i].bv_len);
654 len += entry_lenlen(i);
655 nval++; /* empty berval at end */
656 if (norm && a->a_nvals != a->a_vals) {
657 for (i=0; a->a_nvals[i].bv_val; i++) {
659 len += a->a_nvals[i].bv_len + 1;
660 len += entry_lenlen(a->a_nvals[i].bv_len);
662 len += entry_lenlen(i); /* i nvals */
665 len += entry_lenlen(0); /* 0 nvals */
668 len += entry_lenlen(nat);
669 len += entry_lenlen(nval);
675 /* Add up the size of the entry for a flattened buffer */
676 ber_len_t entry_flatsize(Entry *e, int norm)
681 entry_partsize(e, &len, &nattrs, &nvals, norm);
682 len += sizeof(Entry) + (nattrs * sizeof(Attribute)) +
683 (nvals * sizeof(struct berval));
687 /* Flatten an Entry into a buffer. The buffer is filled with just the
688 * strings/bervals of all the entry components. Each field is preceded
689 * by its length, encoded the way ber_put_len works. Every field is NUL
690 * terminated. The entire buffer size is precomputed so that a single
691 * malloc can be performed. The entry size is also recorded,
692 * to aid in entry_decode.
694 int entry_encode(Entry *e, struct berval *bv)
696 ber_len_t len, dnlen, ndnlen, i;
701 Debug( LDAP_DEBUG_TRACE, "=> entry_encode(0x%08lx): %s\n",
702 (long) e->e_id, e->e_dn, 0 );
704 dnlen = e->e_name.bv_len;
705 ndnlen = e->e_nname.bv_len;
707 entry_partsize( e, &len, &nattrs, &nvals, 1 );
710 bv->bv_val = ch_malloc(len);
711 ptr = (unsigned char *)bv->bv_val;
712 entry_putlen(&ptr, nattrs);
713 entry_putlen(&ptr, nvals);
714 entry_putlen(&ptr, dnlen);
715 AC_MEMCPY(ptr, e->e_dn, dnlen);
718 entry_putlen(&ptr, ndnlen);
719 AC_MEMCPY(ptr, e->e_ndn, ndnlen);
723 for (a=e->e_attrs; a; a=a->a_next) {
724 entry_putlen(&ptr, a->a_desc->ad_cname.bv_len);
725 AC_MEMCPY(ptr, a->a_desc->ad_cname.bv_val,
726 a->a_desc->ad_cname.bv_len);
727 ptr += a->a_desc->ad_cname.bv_len;
730 for (i=0; a->a_vals[i].bv_val; i++);
731 assert( i == a->a_numvals );
732 entry_putlen(&ptr, i);
733 for (i=0; a->a_vals[i].bv_val; i++) {
734 entry_putlen(&ptr, a->a_vals[i].bv_len);
735 AC_MEMCPY(ptr, a->a_vals[i].bv_val,
736 a->a_vals[i].bv_len);
737 ptr += a->a_vals[i].bv_len;
740 if (a->a_nvals != a->a_vals) {
741 entry_putlen(&ptr, i);
742 for (i=0; a->a_nvals[i].bv_val; i++) {
743 entry_putlen(&ptr, a->a_nvals[i].bv_len);
744 AC_MEMCPY(ptr, a->a_nvals[i].bv_val,
745 a->a_nvals[i].bv_len);
746 ptr += a->a_nvals[i].bv_len;
750 entry_putlen(&ptr, 0);
755 Debug( LDAP_DEBUG_TRACE, "<= entry_encode(0x%08lx): %s\n",
756 (long) e->e_id, e->e_dn, 0 );
761 /* Retrieve an Entry that was stored using entry_encode above.
762 * First entry_header must be called to decode the size of the entry.
763 * Then a single block of memory must be malloc'd to accomodate the
764 * bervals and the bulk data. Next the bulk data is retrieved from
765 * the DB and parsed by entry_decode.
767 * Note: everything is stored in a single contiguous block, so
768 * you can not free individual attributes or names from this
769 * structure. Attempting to do so will likely corrupt memory.
771 int entry_header(EntryHeader *eh)
773 unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
775 /* Some overlays can create empty entries
776 * so don't check for zeros here.
778 eh->nattrs = entry_getlen(&ptr);
779 eh->nvals = entry_getlen(&ptr);
780 eh->data = (char *)ptr;
785 entry_decode_dn( EntryHeader *eh, struct berval *dn, struct berval *ndn )
788 unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
790 assert( dn != NULL || ndn != NULL );
792 ptr = (unsigned char *)eh->data;
793 i = entry_getlen(&ptr);
795 dn->bv_val = (char *) ptr;
801 i = entry_getlen(&ptr);
802 ndn->bv_val = (char *) ptr;
806 Debug( LDAP_DEBUG_TRACE,
807 "entry_decode_dn: \"%s\"\n",
808 dn ? dn->bv_val : ndn->bv_val, 0, 0 );
813 #ifdef SLAP_ZONE_ALLOC
814 int entry_decode(EntryHeader *eh, Entry **e, void *ctx)
816 int entry_decode(EntryHeader *eh, Entry **e)
819 int i, j, nattrs, nvals;
824 AttributeDescription *ad;
825 unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
831 x->e_attrs = attrs_alloc( nattrs );
832 ptr = (unsigned char *)eh->data;
833 i = entry_getlen(&ptr);
834 x->e_name.bv_val = (char *) ptr;
835 x->e_name.bv_len = i;
837 i = entry_getlen(&ptr);
838 x->e_nname.bv_val = (char *) ptr;
839 x->e_nname.bv_len = i;
841 Debug( LDAP_DEBUG_TRACE,
842 "entry_decode: \"%s\"\n",
847 bptr = (BerVarray)eh->bv.bv_val;
849 while ((i = entry_getlen(&ptr))) {
852 bv.bv_val = (char *) ptr;
854 rc = slap_bv2ad( &bv, &ad, &text );
856 if( rc != LDAP_SUCCESS ) {
857 Debug( LDAP_DEBUG_TRACE,
858 "<= entry_decode: str2ad(%s): %s\n", ptr, text, 0 );
859 rc = slap_bv2undef_ad( &bv, &ad, &text, 0 );
861 if( rc != LDAP_SUCCESS ) {
862 Debug( LDAP_DEBUG_ANY,
863 "<= entry_decode: slap_str2undef_ad(%s): %s\n",
870 a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
871 j = entry_getlen(&ptr);
876 i = entry_getlen(&ptr);
878 bptr->bv_val = (char *)ptr;
887 j = entry_getlen(&ptr);
891 i = entry_getlen(&ptr);
893 bptr->bv_val = (char *)ptr;
902 a->a_nvals = a->a_vals;
904 /* FIXME: This is redundant once a sorted entry is saved into the DB */
905 if ( a->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) {
906 rc = slap_sort_vals( (Modifications *)a, &text, &j, NULL );
907 if ( rc == LDAP_SUCCESS ) {
908 a->a_flags |= SLAP_ATTR_SORTED_VALS;
909 } else if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
910 /* should never happen */
911 Debug( LDAP_DEBUG_ANY,
912 "entry_decode: attributeType %s value #%d provided more than once\n",
913 a->a_desc->ad_cname.bv_val, j, 0 );
923 Debug(LDAP_DEBUG_TRACE, "<= entry_decode(%s)\n",
930 entry_dup2( Entry *dest, Entry *source )
932 assert( dest != NULL );
933 assert( source != NULL );
935 assert( dest->e_private == NULL );
937 dest->e_id = source->e_id;
938 ber_dupbv( &dest->e_name, &source->e_name );
939 ber_dupbv( &dest->e_nname, &source->e_nname );
940 dest->e_attrs = attrs_dup( source->e_attrs );
941 dest->e_ocflags = source->e_ocflags;
947 entry_dup( Entry *e )
949 return entry_dup2( entry_alloc(), e );
953 /* Duplicates an entry using a single malloc. Saves CPU time, increases
954 * heap usage because a single large malloc is harder to satisfy than
955 * lots of small ones, and the freed space isn't as easily reusable.
957 * Probably not worth using this function.
959 Entry *entry_dup_bv( Entry *e )
966 Attribute *src, *dst;
970 entry_partsize(e, &len, &nattrs, &nvals, 1);
972 ret->e_attrs = attrs_alloc( nattrs );
973 ret->e_ocflags = e->e_ocflags;
974 ret->e_bv.bv_len = len + nvals * sizeof(struct berval);
975 ret->e_bv.bv_val = ch_malloc( ret->e_bv.bv_len );
977 bvl = (struct berval *)ret->e_bv.bv_val;
978 ptr = (char *)(bvl + nvals);
980 ret->e_name.bv_len = e->e_name.bv_len;
981 ret->e_name.bv_val = ptr;
982 AC_MEMCPY( ptr, e->e_name.bv_val, e->e_name.bv_len );
983 ptr += e->e_name.bv_len;
986 ret->e_nname.bv_len = e->e_nname.bv_len;
987 ret->e_nname.bv_val = ptr;
988 AC_MEMCPY( ptr, e->e_nname.bv_val, e->e_nname.bv_len );
989 ptr += e->e_name.bv_len;
993 for (src = e->e_attrs; src; src=src->a_next,dst=dst->a_next ) {
995 dst->a_desc = src->a_desc;
996 dst->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
998 dst->a_numvals = src->a_numvals;
999 for ( i=0; src->a_vals[i].bv_val; i++ ) {
1000 bvl->bv_len = src->a_vals[i].bv_len;
1002 AC_MEMCPY( ptr, src->a_vals[i].bv_val, bvl->bv_len );
1009 if ( src->a_vals != src->a_nvals ) {
1011 for ( i=0; src->a_nvals[i].bv_val; i++ ) {
1012 bvl->bv_len = src->a_nvals[i].bv_len;
1014 AC_MEMCPY( ptr, src->a_nvals[i].bv_val, bvl->bv_len );