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