]> git.sur5r.net Git - openldap/blob - servers/slapd/entry.c
ComponentFilterMatch support for userCertificate
[openldap] / servers / slapd / entry.c
1 /* entry.c - routines for dealing with entries */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 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 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
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.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/ctype.h>
32 #include <ac/errno.h>
33 #include <ac/socket.h>
34 #include <ac/string.h>
35
36 #include "slap.h"
37 #include "ldif.h"
38
39 static unsigned char    *ebuf;  /* buf returned by entry2str             */
40 static unsigned char    *ecur;  /* pointer to end of currently used ebuf */
41 static int              emaxsize;/* max size of ebuf                     */
42
43 /*
44  * Empty root entry
45  */
46 const Entry slap_entry_root = {
47         NOID, { 0, "" }, { 0, "" }, NULL, 0, { 0, "" }, NULL
48 };
49
50 int entry_destroy(void)
51 {
52         if ( ebuf ) free( ebuf );
53         ebuf = NULL;
54         ecur = NULL;
55         emaxsize = 0;
56         return 0;
57 }
58
59
60 Entry *
61 str2entry( char *s )
62 {
63         int rc;
64         Entry           *e;
65         char            *type;
66         struct berval   vals[2];
67         struct berval   nvals[2], *nvalsp;
68         AttributeDescription *ad, *ad_prev;
69         const char *text;
70         char    *next;
71         int             attr_cnt;
72
73         /*
74          * LDIF is used as the string format.
75          * An entry looks like this:
76          *
77          *      dn: <dn>\n
78          *      [<attr>:[:] <value>\n]
79          *      [<tab><continuedvalue>\n]*
80          *      ...
81          *
82          * If a double colon is used after a type, it means the
83          * following value is encoded as a base 64 string.  This
84          * happens if the value contains a non-printing character
85          * or newline.
86          */
87
88         Debug( LDAP_DEBUG_TRACE, "=> str2entry: \"%s\"\n",
89                 s ? s : "NULL", 0, 0 );
90
91         /* initialize reader/writer lock */
92         e = (Entry *) ch_calloc( 1, sizeof(Entry) );
93
94         if( e == NULL ) {
95                 Debug( LDAP_DEBUG_ANY,
96                     "<= str2entry NULL (entry allocation failed)\n",
97                     0, 0, 0 );
98                 return( NULL );
99         }
100
101         /* initialize entry */
102         e->e_id = NOID;
103
104         /* dn + attributes */
105         vals[1].bv_len = 0;
106         vals[1].bv_val = NULL;
107
108         ad = NULL;
109         ad_prev = NULL;
110         attr_cnt = 0;
111         next = s;
112         while ( (s = ldif_getline( &next )) != NULL ) {
113                 if ( *s == '\n' || *s == '\0' ) {
114                         break;
115                 }
116
117                 if ( ldif_parse_line( s, &type, &vals[0].bv_val, &vals[0].bv_len ) != 0 ) {
118                         Debug( LDAP_DEBUG_TRACE,
119                             "<= str2entry NULL (parse_line)\n", 0, 0, 0 );
120                         continue;
121                 }
122
123                 if ( strcasecmp( type, "dn" ) == 0 ) {
124                         free( type );
125
126                         if ( e->e_dn != NULL ) {
127                                 Debug( LDAP_DEBUG_ANY, "str2entry: "
128                                         "entry %ld has multiple DNs \"%s\" and \"%s\"\n",
129                                     (long) e->e_id, e->e_dn, vals[0].bv_val );
130                                 free( vals[0].bv_val );
131                                 entry_free( e );
132                                 return NULL;
133                         }
134
135                         rc = dnPrettyNormal( NULL, &vals[0], &e->e_name, &e->e_nname, NULL );
136                         if( rc != LDAP_SUCCESS ) {
137                                 Debug( LDAP_DEBUG_ANY, "str2entry: "
138                                         "entry %ld has invalid DN \"%s\"\n",
139                                         (long) e->e_id, vals[0].bv_val, 0 );
140                                 entry_free( e );
141                                 free( vals[0].bv_val );
142                                 return NULL;
143                         }
144                         free( vals[0].bv_val );
145                         continue;
146                 }
147
148                 ad_prev = ad;
149                 ad = NULL;
150                 rc = slap_str2ad( type, &ad, &text );
151
152                 if( rc != LDAP_SUCCESS ) {
153                         Debug( slapMode & SLAP_TOOL_MODE
154                                 ? LDAP_DEBUG_ANY : LDAP_DEBUG_TRACE,
155                                 "<= str2entry: str2ad(%s): %s\n", type, text, 0 );
156                         if( slapMode & SLAP_TOOL_MODE ) {
157                                 entry_free( e );
158                                 free( vals[0].bv_val );
159                                 free( type );
160                                 return NULL;
161                         }
162
163                         rc = slap_str2undef_ad( type, &ad, &text );
164                         if( rc != LDAP_SUCCESS ) {
165                                 Debug( LDAP_DEBUG_ANY,
166                                         "<= str2entry: str2undef_ad(%s): %s\n",
167                                                 type, text, 0 );
168                                 entry_free( e );
169                                 free( vals[0].bv_val );
170                                 free( type );
171                                 return NULL;
172                         }
173                 }
174
175                 if ( ad != ad_prev ) {
176                         attr_cnt = 0;
177                 }
178
179                 if( slapMode & SLAP_TOOL_MODE ) {
180                         struct berval pval;
181                         slap_syntax_validate_func *validate =
182                                 ad->ad_type->sat_syntax->ssyn_validate;
183                         slap_syntax_transform_func *pretty =
184                                 ad->ad_type->sat_syntax->ssyn_pretty;
185
186                         if( pretty ) {
187                                 rc = pretty( ad->ad_type->sat_syntax,
188                                         &vals[0], &pval, NULL );
189
190                         } else if( validate ) {
191                                 /*
192                                  * validate value per syntax
193                                  */
194                                 rc = validate( ad->ad_type->sat_syntax, &vals[0] );
195
196                         } else {
197                                 Debug( LDAP_DEBUG_ANY,
198                                         "str2entry: attributeType %s #%d: "
199                                         "no validator for syntax %s\n", 
200                                         ad->ad_cname.bv_val, attr_cnt,
201                                         ad->ad_type->sat_syntax->ssyn_oid );
202                                 entry_free( e );
203                                 free( vals[0].bv_val );
204                                 free( type );
205                                 return NULL;
206                         }
207
208                         if( rc != 0 ) {
209                                 Debug( LDAP_DEBUG_ANY,
210                                         "str2entry: invalid value "
211                                         "for attributeType %s #%d (syntax %s)\n",
212                                         ad->ad_cname.bv_val, attr_cnt,
213                                         ad->ad_type->sat_syntax->ssyn_oid );
214                                 entry_free( e );
215                                 free( vals[0].bv_val );
216                                 free( type );
217                                 return NULL;
218                         }
219
220                         if( pretty ) {
221                                 free( vals[0].bv_val );
222                                 vals[0] = pval;
223                         }
224                 }
225
226                 nvalsp = NULL;
227                 nvals[0].bv_val = NULL;
228
229                 if( ad->ad_type->sat_equality &&
230                         ad->ad_type->sat_equality->smr_normalize )
231                 {
232                         rc = ad->ad_type->sat_equality->smr_normalize(
233                                 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
234                                 ad->ad_type->sat_syntax,
235                                 ad->ad_type->sat_equality,
236                                 &vals[0], &nvals[0], NULL );
237
238                         if( rc ) {
239                                 Debug( LDAP_DEBUG_ANY,
240                                         "<= str2entry NULL (smr_normalize %d)\n", rc, 0, 0 );
241
242                                 entry_free( e );
243                                 free( vals[0].bv_val );
244                                 free( type );
245                                 return NULL;
246                         }
247
248                         nvals[1].bv_len = 0;
249                         nvals[1].bv_val = NULL;
250
251                         nvalsp = &nvals[0];
252                 }
253
254                 rc = attr_merge( e, ad, vals, nvalsp );
255                 if( rc != 0 ) {
256                         Debug( LDAP_DEBUG_ANY,
257                             "<= str2entry NULL (attr_merge)\n", 0, 0, 0 );
258                         entry_free( e );
259                         free( vals[0].bv_val );
260                         free( type );
261                         return( NULL );
262                 }
263
264                 free( type );
265                 free( vals[0].bv_val );
266                 free( nvals[0].bv_val );
267
268                 attr_cnt++;
269         }
270
271         /* check to make sure there was a dn: line */
272         if ( e->e_dn == NULL ) {
273                 Debug( LDAP_DEBUG_ANY, "str2entry: entry %ld has no dn\n",
274                     (long) e->e_id, 0, 0 );
275                 entry_free( e );
276                 return NULL;
277         }
278
279         Debug(LDAP_DEBUG_TRACE, "<= str2entry(%s) -> 0x%lx\n",
280                 e->e_dn, (unsigned long) e, 0 );
281         return( e );
282 }
283
284
285 #define GRABSIZE        BUFSIZ
286
287 #define MAKE_SPACE( n ) { \
288                 while ( ecur + (n) > ebuf + emaxsize ) { \
289                         ptrdiff_t       offset; \
290                         offset = (int) (ecur - ebuf); \
291                         ebuf = (unsigned char *) ch_realloc( (char *) ebuf, \
292                             emaxsize + GRABSIZE ); \
293                         emaxsize += GRABSIZE; \
294                         ecur = ebuf + offset; \
295                 } \
296         }
297
298 char *
299 entry2str(
300     Entry       *e,
301     int         *len )
302 {
303         Attribute       *a;
304         struct berval   *bv;
305         int             i;
306         ber_len_t tmplen;
307
308         assert( e != NULL );
309
310         /*
311          * In string format, an entry looks like this:
312          *      dn: <dn>\n
313          *      [<attr>: <value>\n]*
314          */
315
316         ecur = ebuf;
317
318         /* put the dn */
319         if ( e->e_dn != NULL ) {
320                 /* put "dn: <dn>" */
321                 tmplen = e->e_name.bv_len;
322                 MAKE_SPACE( LDIF_SIZE_NEEDED( 2, tmplen ));
323                 ldif_sput( (char **) &ecur, LDIF_PUT_VALUE, "dn", e->e_dn, tmplen );
324         }
325
326         /* put the attributes */
327         for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
328                 /* put "<type>:[:] <value>" line for each value */
329                 for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
330                         bv = &a->a_vals[i];
331                         tmplen = a->a_desc->ad_cname.bv_len;
332                         MAKE_SPACE( LDIF_SIZE_NEEDED( tmplen, bv->bv_len ));
333                         ldif_sput( (char **) &ecur, LDIF_PUT_VALUE,
334                                 a->a_desc->ad_cname.bv_val,
335                             bv->bv_val, bv->bv_len );
336                 }
337         }
338         MAKE_SPACE( 1 );
339         *ecur = '\0';
340         *len = ecur - ebuf;
341
342         return( (char *) ebuf );
343 }
344
345 void
346 entry_clean( Entry *e )
347 {
348         /* free an entry structure */
349         assert( e != NULL );
350
351         /* e_private must be freed by the caller */
352         assert( e->e_private == NULL );
353         e->e_private = NULL;
354
355         /* free DNs */
356         if ( !BER_BVISNULL( &e->e_name ) ) {
357                 free( e->e_name.bv_val );
358                 BER_BVZERO( &e->e_name );
359         }
360         if ( !BER_BVISNULL( &e->e_nname ) ) {
361                 free( e->e_nname.bv_val );
362                 BER_BVZERO( &e->e_nname );
363         }
364
365         if ( !BER_BVISNULL( &e->e_bv ) ) {
366                 free( e->e_bv.bv_val );
367                 BER_BVZERO( &e->e_bv );
368         }
369
370         /* free attributes */
371         attrs_free( e->e_attrs );
372         e->e_attrs = NULL;
373 }
374
375 void
376 entry_free( Entry *e )
377 {
378         entry_clean( e );
379
380         free( e );
381 }
382
383 /*
384  * These routines are used only by Backend.
385  *
386  * the Entry has three entry points (ways to find things):
387  *
388  *      by entry        e.g., if you already have an entry from the cache
389  *                      and want to delete it. (really by entry ptr)
390  *      by dn           e.g., when looking for the base object of a search
391  *      by id           e.g., for search candidates
392  *
393  * these correspond to three different avl trees that are maintained.
394  */
395
396 int
397 entry_cmp( Entry *e1, Entry *e2 )
398 {
399         return SLAP_PTRCMP( e1, e2 );
400 }
401
402 int
403 entry_dn_cmp( const void *v_e1, const void *v_e2 )
404 {
405         /* compare their normalized UPPERCASED dn's */
406         const Entry *e1 = v_e1, *e2 = v_e2;
407
408         return ber_bvcmp( &e1->e_nname, &e2->e_nname );
409 }
410
411 int
412 entry_id_cmp( const void *v_e1, const void *v_e2 )
413 {
414         const Entry *e1 = v_e1, *e2 = v_e2;
415         return( e1->e_id < e2->e_id ? -1 : (e1->e_id > e2->e_id ? 1 : 0) );
416 }
417
418 #define entry_lenlen(l) ((l) < 0x80) ? 1 : ((l) < 0x100) ? 2 : \
419         ((l) < 0x10000) ? 3 : ((l) < 0x1000000) ? 4 : 5
420 #if 0
421 /* This is like a ber_len */
422 static ber_len_t
423 entry_lenlen(ber_len_t len)
424 {
425         if (len <= 0x7f)
426                 return 1;
427         if (len <= 0xff)
428                 return 2;
429         if (len <= 0xffff)
430                 return 3;
431         if (len <= 0xffffff)
432                 return 4;
433         return 5;
434 }
435 #endif
436
437 static void
438 entry_putlen(unsigned char **buf, ber_len_t len)
439 {
440         ber_len_t lenlen = entry_lenlen(len);
441
442         if (lenlen == 1) {
443                 **buf = (unsigned char) len;
444         } else {
445                 int i;
446                 **buf = 0x80 | ((unsigned char) lenlen - 1);
447                 for (i=lenlen-1; i>0; i--) {
448                         (*buf)[i] = (unsigned char) len;
449                         len >>= 8;
450                 }
451         }
452         *buf += lenlen;
453 }
454
455 static ber_len_t
456 entry_getlen(unsigned char **buf)
457 {
458         ber_len_t len;
459         int i;
460
461         len = *(*buf)++;
462         if (len <= 0x7f)
463                 return len;
464         i = len & 0x7f;
465         len = 0;
466         for (;i > 0; i--) {
467                 len <<= 8;
468                 len |= *(*buf)++;
469         }
470         return len;
471 }
472
473 /* Add up the size of the entry for a flattened buffer */
474 void entry_flatsize(Entry *e, ber_len_t *psiz, ber_len_t *plen, int norm)
475 {
476         ber_len_t siz = sizeof(Entry);
477         ber_len_t len, dnlen, ndnlen;
478         int i;
479         Attribute *a;
480
481         dnlen = e->e_name.bv_len;
482         len = dnlen + 1;        /* trailing NUL byte */
483         len += entry_lenlen(dnlen);
484         if (norm) {
485                 ndnlen = e->e_nname.bv_len;
486                 len += ndnlen + 1;
487                 len += entry_lenlen(ndnlen);
488         }
489         for (a=e->e_attrs; a; a=a->a_next) {
490                 /* For AttributeDesc, we only store the attr name */
491                 siz += sizeof(Attribute);
492                 len += a->a_desc->ad_cname.bv_len+1;
493                 len += entry_lenlen(a->a_desc->ad_cname.bv_len);
494                 for (i=0; a->a_vals[i].bv_val; i++) {
495                         siz += sizeof(struct berval);
496                         len += a->a_vals[i].bv_len + 1;
497                         len += entry_lenlen(a->a_vals[i].bv_len);
498                 }
499                 len += entry_lenlen(i);
500                 siz += sizeof(struct berval);   /* empty berval at end */
501                 if (norm && a->a_nvals != a->a_vals) {
502                         for (i=0; a->a_nvals[i].bv_val; i++) {
503                                 siz += sizeof(struct berval);
504                                 len += a->a_nvals[i].bv_len + 1;
505                                 len += entry_lenlen(a->a_nvals[i].bv_len);
506                         }
507                         len += entry_lenlen(i); /* i nvals */
508                         siz += sizeof(struct berval);
509                 } else {
510                         len += entry_lenlen(0); /* 0 nvals */
511                 }
512         }
513         len += 1;       /* NUL byte at end */
514         len += entry_lenlen(siz);
515         *psiz = siz;
516         *plen = len;
517 }
518
519 /* Flatten an Entry into a buffer. The buffer is filled with just the
520  * strings/bervals of all the entry components. Each field is preceded
521  * by its length, encoded the way ber_put_len works. Every field is NUL
522  * terminated.  The entire buffer size is precomputed so that a single
523  * malloc can be performed. The entry size is also recorded,
524  * to aid in entry_decode.
525  */
526 int entry_encode(Entry *e, struct berval *bv)
527 {
528         ber_len_t siz = sizeof(Entry);
529         ber_len_t len, dnlen, ndnlen;
530         int i;
531         Attribute *a;
532         unsigned char *ptr;
533
534         Debug( LDAP_DEBUG_TRACE, "=> entry_encode(0x%08lx): %s\n",
535                 (long) e->e_id, e->e_dn, 0 );
536         dnlen = e->e_name.bv_len;
537         ndnlen = e->e_nname.bv_len;
538
539         entry_flatsize( e, &siz, &len, 1 );
540
541         bv->bv_len = len;
542         bv->bv_val = ch_malloc(len);
543         ptr = (unsigned char *)bv->bv_val;
544         entry_putlen(&ptr, siz);
545         entry_putlen(&ptr, dnlen);
546         AC_MEMCPY(ptr, e->e_dn, dnlen);
547         ptr += dnlen;
548         *ptr++ = '\0';
549         entry_putlen(&ptr, ndnlen);
550         AC_MEMCPY(ptr, e->e_ndn, ndnlen);
551         ptr += ndnlen;
552         *ptr++ = '\0';
553
554         for (a=e->e_attrs; a; a=a->a_next) {
555                 entry_putlen(&ptr, a->a_desc->ad_cname.bv_len);
556                 AC_MEMCPY(ptr, a->a_desc->ad_cname.bv_val,
557                         a->a_desc->ad_cname.bv_len);
558                 ptr += a->a_desc->ad_cname.bv_len;
559                 *ptr++ = '\0';
560                 if (a->a_vals) {
561                     for (i=0; a->a_vals[i].bv_val; i++);
562                     entry_putlen(&ptr, i);
563                     for (i=0; a->a_vals[i].bv_val; i++) {
564                         entry_putlen(&ptr, a->a_vals[i].bv_len);
565                         AC_MEMCPY(ptr, a->a_vals[i].bv_val,
566                                 a->a_vals[i].bv_len);
567                         ptr += a->a_vals[i].bv_len;
568                         *ptr++ = '\0';
569                     }
570                     if (a->a_nvals != a->a_vals) {
571                         entry_putlen(&ptr, i);
572                         for (i=0; a->a_nvals[i].bv_val; i++) {
573                             entry_putlen(&ptr, a->a_nvals[i].bv_len);
574                             AC_MEMCPY(ptr, a->a_nvals[i].bv_val,
575                                 a->a_nvals[i].bv_len);
576                             ptr += a->a_nvals[i].bv_len;
577                             *ptr++ = '\0';
578                         }
579                     } else {
580                         entry_putlen(&ptr, 0);
581                     }
582                 }
583         }
584         *ptr = '\0';
585         return 0;
586 }
587
588 /* Retrieve an Entry that was stored using entry_encode above.
589  * We malloc a single block with the size stored above for the Entry
590  * and all of its Attributes. We also must lookup the stored
591  * attribute names to get AttributeDescriptions. To detect if the
592  * attributes of an Entry are later modified, we note that e->e_attr
593  * is always a constant offset from (e).
594  *
595  * Note: everything is stored in a single contiguous block, so
596  * you can not free individual attributes or names from this
597  * structure. Attempting to do so will likely corrupt memory.
598  */
599 int entry_decode(struct berval *bv, Entry **e)
600 {
601         int i, j, count;
602         int rc;
603         Attribute *a;
604         Entry *x;
605         const char *text;
606         AttributeDescription *ad;
607         unsigned char *ptr = (unsigned char *)bv->bv_val;
608         BerVarray bptr;
609
610         i = entry_getlen(&ptr);
611         if (!i) {
612                 Debug( LDAP_DEBUG_ANY,
613                         "entry_decode: entry length was zero\n", 0, 0, 0);
614                 return LDAP_OTHER;
615         }
616         x = ch_calloc(1, i);
617         i = entry_getlen(&ptr);
618         x->e_name.bv_val = (char *) ptr;
619         x->e_name.bv_len = i;
620         ptr += i+1;
621         i = entry_getlen(&ptr);
622         x->e_nname.bv_val = (char *) ptr;
623         x->e_nname.bv_len = i;
624         ptr += i+1;
625         Debug( LDAP_DEBUG_TRACE,
626             "entry_decode: \"%s\"\n",
627             x->e_dn, 0, 0 );
628         x->e_bv = *bv;
629
630         /* A valid entry must have at least one attr, so this
631          * pointer can never be NULL
632          */
633         x->e_attrs = (Attribute *)(x+1);
634         bptr = (BerVarray)x->e_attrs;
635         a = NULL;
636
637         while ((i = entry_getlen(&ptr))) {
638                 struct berval bv;
639                 bv.bv_len = i;
640                 bv.bv_val = (char *) ptr;
641                 if (a) {
642                         a->a_next = (Attribute *)bptr;
643                 }
644                 a = (Attribute *)bptr;
645                 ad = NULL;
646                 rc = slap_bv2ad( &bv, &ad, &text );
647
648                 if( rc != LDAP_SUCCESS ) {
649                         Debug( LDAP_DEBUG_TRACE,
650                                 "<= entry_decode: str2ad(%s): %s\n", ptr, text, 0 );
651                         rc = slap_bv2undef_ad( &bv, &ad, &text );
652
653                         if( rc != LDAP_SUCCESS ) {
654                                 Debug( LDAP_DEBUG_ANY,
655                                         "<= entry_decode: str2undef_ad(%s): %s\n",
656                                                 ptr, text, 0 );
657                                 return rc;
658                         }
659                 }
660                 ptr += i + 1;
661                 a->a_desc = ad;
662                 bptr = (BerVarray)(a+1);
663                 a->a_vals = bptr;
664                 a->a_flags = 0;
665 #ifdef LDAP_COMP_MATCH
666                 a->a_component_values = NULL;
667 #endif
668                 count = j = entry_getlen(&ptr);
669
670                 while (j) {
671                         i = entry_getlen(&ptr);
672                         bptr->bv_len = i;
673                         bptr->bv_val = (char *)ptr;
674                         ptr += i+1;
675                         bptr++;
676                         j--;
677                 }
678                 bptr->bv_val = NULL;
679                 bptr->bv_len = 0;
680                 bptr++;
681
682                 j = entry_getlen(&ptr);
683                 if (j) {
684                         a->a_nvals = bptr;
685                         while (j) {
686                                 i = entry_getlen(&ptr);
687                                 bptr->bv_len = i;
688                                 bptr->bv_val = (char *)ptr;
689                                 ptr += i+1;
690                                 bptr++;
691                                 j--;
692                         }
693                         bptr->bv_val = NULL;
694                         bptr->bv_len = 0;
695                         bptr++;
696                 } else {
697                         a->a_nvals = a->a_vals;
698                 }
699         }
700
701         if (a) a->a_next = NULL;
702         Debug(LDAP_DEBUG_TRACE, "<= entry_decode(%s)\n",
703                 x->e_dn, 0, 0 );
704         *e = x;
705         return 0;
706 }
707
708 Entry *entry_dup( Entry *e )
709 {
710         Entry *ret;
711
712         ret = (Entry *)ch_calloc( 1, sizeof(*ret) );
713
714         ret->e_id = e->e_id;
715         ber_dupbv( &ret->e_name, &e->e_name );
716         ber_dupbv( &ret->e_nname, &e->e_nname );
717         ret->e_attrs = attrs_dup( e->e_attrs );
718         ret->e_ocflags = e->e_ocflags;
719         ret->e_bv.bv_val = NULL;
720         ret->e_bv.bv_len = 0;
721         ret->e_private = NULL;
722
723         return ret;
724 }
725