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