]> git.sur5r.net Git - openldap/blob - servers/slapd/result.c
Fix maxDeref directive
[openldap] / servers / slapd / result.c
1 /* result.c - routines to send ldap results, errors, and referrals */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/errno.h>
9 #include <ac/signal.h>
10 #include <ac/string.h>
11 #include <ac/time.h>
12 #include <ac/unistd.h>
13
14 #include "slap.h"
15
16 /* we need LBER internals */
17 #include "../../libraries/liblber/lber-int.h"
18
19 static char *v2ref( struct berval **ref )
20 {
21         size_t len, i;
22         char *v2;
23
24         if(ref == NULL) return NULL;
25
26         len = sizeof("Referral:");
27         v2 = ch_strdup("Referral:");
28
29         for( i=0; ref[i] != NULL; i++ ) {
30                 v2 = ch_realloc( v2, len + ref[i]->bv_len + 1 );
31                 v2[len-1] = '\n';
32                 memcpy(&v2[len], ref[i]->bv_val, ref[i]->bv_len );
33                 len += ref[i]->bv_len;
34         }
35
36         v2[len-1] = '\0';
37         return v2;
38 }
39
40 static ber_tag_t req2res( ber_tag_t tag )
41 {
42         switch( tag ) {
43         case LDAP_REQ_ADD:
44         case LDAP_REQ_BIND:
45         case LDAP_REQ_COMPARE:
46         case LDAP_REQ_EXTENDED:
47         case LDAP_REQ_MODIFY:
48         case LDAP_REQ_MODRDN:
49                 tag++;
50                 break;
51
52         case LDAP_REQ_DELETE:
53                 tag = LDAP_RES_DELETE;
54                 break;
55
56         case LDAP_REQ_ABANDON:
57         case LDAP_REQ_UNBIND:
58                 tag = LBER_SEQUENCE;
59                 break;
60
61         case LDAP_REQ_SEARCH:
62                 tag = LDAP_RES_SEARCH_RESULT;
63                 break;
64
65         default:
66                 assert( 0 );
67                 tag = LBER_ERROR;
68         }
69         return tag;
70 }
71
72 static void trim_refs_urls(
73         struct berval **refs )
74 {
75         unsigned i;
76
77         if( refs == NULL ) return;
78
79         for( i=0; refs[i] != NULL; i++ ) {
80                 if(     refs[i]->bv_len > sizeof("ldap://") &&
81                         strncasecmp( refs[i]->bv_val, "ldap://",
82                                 sizeof("ldap://")-1 ) == 0 )
83                 {
84                         unsigned j;
85                         for( j=sizeof("ldap://"); j<refs[i]->bv_len ; j++ ) {
86                                 if( refs[i]->bv_val[j] = '/' ) {
87                                         refs[i]->bv_val[j] = '\0';
88                                         refs[i]->bv_len = j;
89                                         break;
90                                 }
91                         }
92                 }
93         }
94 }
95
96 struct berval **get_entry_referrals(
97         Backend *be,
98         Connection *conn,
99         Operation *op,
100         Entry *e )
101 {
102         Attribute *attr;
103         struct berval **refs;
104         unsigned i, j;
105
106         attr = attr_find( e->e_attrs, "ref" );
107
108         if( attr == NULL ) return NULL;
109
110         for( i=0; attr->a_vals[i] != NULL; i++ ) {
111                 /* count references */
112         }
113
114         if( i < 1 ) return NULL;
115
116         refs = ch_malloc( i + 1 );
117
118         for( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
119                 unsigned k;
120                 struct berval *ref = ber_bvdup( attr->a_vals[i] );
121
122                 /* trim the label */
123                 for( k=0; k<ref->bv_len; k++ ) {
124                         if( isspace(ref->bv_val[k]) ) {
125                                 ref->bv_val[k] = '\0';
126                                 ref->bv_len = k;
127                                 break;
128                         }
129                 }
130
131                 if(     ref->bv_len > 0 ) {
132                         refs[j++] = ref;
133
134                 } else {
135                         ber_bvfree( ref );
136                 }
137         }
138
139         refs[j] = NULL;
140
141         if( j == 0 ) {
142                 ber_bvecfree( refs );
143                 refs = NULL;
144         }
145
146         /* we should check that a referral value exists... */
147
148         return refs;
149 }
150
151 static long send_ldap_ber(
152         Connection *conn,
153         BerElement *ber )
154 {
155         ber_len_t bytes = ber_pvt_ber_bytes( ber );
156
157         /* write only one pdu at a time - wait til it's our turn */
158         ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
159
160         /* lock the connection */ 
161         ldap_pvt_thread_mutex_lock( &conn->c_mutex );
162
163         /* write the pdu */
164         while( 1 ) {
165                 int err;
166
167                 if ( connection_state_closing( conn ) ) {
168                         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
169                         ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
170                         return 0;
171                 }
172
173                 if ( ber_flush( conn->c_sb, ber, 1 ) == 0 ) {
174                         break;
175                 }
176
177                 err = errno;
178
179                 /*
180                  * we got an error.  if it's ewouldblock, we need to
181                  * wait on the socket being writable.  otherwise, figure
182                  * it's a hard error and return.
183                  */
184
185                 Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno %d msg (%s)\n",
186                     err, err > -1 && err < sys_nerr ? sys_errlist[err]
187                     : "unknown", 0 );
188
189                 if ( err != EWOULDBLOCK && err != EAGAIN ) {
190                         connection_closing( conn );
191
192                         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
193                         ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
194                         return( -1 );
195                 }
196
197                 /* wait for socket to be write-ready */
198                 conn->c_writewaiter = 1;
199                 slapd_set_write( ber_pvt_sb_get_desc( conn->c_sb ), 1 );
200
201                 ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
202                 conn->c_writewaiter = 0;
203         }
204
205         ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
206         ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
207
208         return bytes;
209 }
210
211 static void
212 send_ldap_response(
213     Connection  *conn,
214     Operation   *op,
215         ber_tag_t       tag,
216         ber_int_t       msgid,
217     ber_int_t   err,
218     char        *matched,
219     char        *text,
220         struct berval   **ref,
221         char    *resoid,
222         struct berval   *resdata,
223         LDAPControl **ctrls
224 )
225 {
226         BerElement      *ber;
227         int             rc;
228         long    bytes;
229
230         assert( ctrls == NULL ); /* ctrls not implemented */
231
232         ber = ber_alloc_t( LBER_USE_DER );
233
234         Debug( LDAP_DEBUG_TRACE, "send_ldap_response: tag=%ld msgid=%ld err=%ld\n",
235                 (long) tag, (long) msgid, (long) err );
236
237         if ( ber == NULL ) {
238                 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
239                 return;
240         }
241
242 #ifdef LDAP_CONNECTIONLESS
243         if ( op->o_cldap ) {
244                 rc = ber_printf( ber, "{is{t{ess}}}", msgid, "", tag,
245                     err, matched ? matched : "", text ? text : "" );
246         } else
247 #endif
248         {
249                 rc = ber_printf( ber, "{it{ess",
250                         msgid, tag, err,
251                         matched == NULL ? "" : matched,
252                         text == NULL ? "" : text );
253
254                 if( rc != -1 && ref != NULL ) {
255                         rc = ber_printf( ber, "{V}", ref );
256                 }
257
258                 if( rc != -1 && resoid != NULL ) {
259                         rc = ber_printf( ber, "s", resoid );
260                 }
261
262                 if( rc != -1 && resdata != NULL ) {
263                         rc = ber_printf( ber, "O", resdata );
264
265                 }
266
267                 if( rc != -1 ) {
268                         rc = ber_printf( ber, "}}" );
269                 }
270         }
271
272         if ( rc == -1 ) {
273                 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
274                 return;
275         }
276
277         /* send BER */
278         bytes = send_ldap_ber( conn, ber );
279
280         if ( bytes < 0 ) {
281                 Debug( LDAP_DEBUG_ANY,
282                         "send_ldap_response: ber write failed\n",
283                         0, 0, 0 );
284                 return;
285         }
286
287         ldap_pvt_thread_mutex_lock( &num_sent_mutex );
288         num_bytes_sent += bytes;
289         num_pdu_sent++;
290         ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
291         return;
292 }
293
294
295 void
296 send_ldap_disconnect(
297     Connection  *conn,
298     Operation   *op,
299     ber_int_t   err,
300     char        *text
301 )
302 {
303         ber_tag_t tag;
304         ber_int_t msgid;
305         char *reqoid;
306
307 #define LDAP_UNSOLICITED_ERROR(e) \
308         (  (e) == LDAP_PROTOCOL_ERROR \
309         || (e) == LDAP_STRONG_AUTH_REQUIRED \
310         || (e) == LDAP_UNAVAILABLE )
311
312         assert( LDAP_UNSOLICITED_ERROR( err ) );
313
314         Debug( LDAP_DEBUG_TRACE,
315                 "send_ldap_disconnect %d:%s\n",
316                 err, text ? text : "", NULL );
317
318         if ( op->o_protocol < LDAP_VERSION3 ) {
319                 reqoid = NULL;
320                 tag = req2res( op->o_tag );
321                 msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
322
323         } else {
324                 reqoid = LDAP_NOTICE_DISCONNECT;
325                 tag = LDAP_RES_EXTENDED;
326                 msgid = 0;
327         }
328
329 #ifdef LDAP_CONNECTIONLESS
330         if ( op->o_cldap ) {
331                 ber_pvt_sb_udp_set_dst( conn->c_sb, &op->o_clientaddr );
332                 Debug( LDAP_DEBUG_TRACE, "UDP response to %s port %d\n", 
333                     inet_ntoa(((struct sockaddr_in *)
334                     &op->o_clientaddr)->sin_addr ),
335                     ((struct sockaddr_in *) &op->o_clientaddr)->sin_port,
336                     0 );
337         }
338 #endif
339         send_ldap_response( conn, op, tag, msgid,
340                 err, NULL, text, NULL,
341                 reqoid, NULL, NULL );
342
343         Statslog( LDAP_DEBUG_STATS,
344             "conn=%ld op=%ld DISCONNECT err=%ld tag=%lu text=%s\n",
345                 (long) op->o_connid, (long) op->o_opid,
346                 (long) tag, (long) err, text );
347 }
348
349 void
350 send_ldap_result(
351     Connection  *conn,
352     Operation   *op,
353     ber_int_t   err,
354     char        *matched,
355     char        *text,
356         struct berval **ref,
357         LDAPControl **ctrls
358 )
359 {
360         ber_tag_t tag;
361         ber_int_t msgid;
362         char *tmp = NULL;
363
364         assert( !LDAP_API_ERROR( err ) );
365
366         Debug( LDAP_DEBUG_TRACE, "send_ldap_result: conn=%ld op=%ld p=%d\n",
367                 (long) op->o_connid, (long) op->o_opid, op->o_protocol );
368         Debug( LDAP_DEBUG_ARGS, "send_ldap_result: %d:%s:%s\n",
369                 err, matched ?  matched : "", text ? text : "" );
370
371         assert( err != LDAP_PARTIAL_RESULTS );
372
373         if( op->o_tag != LDAP_REQ_SEARCH ) {
374                 trim_refs_urls( ref );
375         }
376
377         if ( err == LDAP_REFERRAL ) {
378                 if( ref == NULL ) {
379                         err = LDAP_NO_SUCH_OBJECT;
380                 } else if ( op->o_protocol < LDAP_VERSION3 ) {
381                         err = LDAP_PARTIAL_RESULTS;
382                         tmp = text = v2ref( ref );
383                         ref = NULL;
384                 }
385         }
386
387         tag = req2res( op->o_tag );
388         msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
389
390 #ifdef LDAP_CONNECTIONLESS
391         if ( op->o_cldap ) {
392                 ber_pvt_sb_udp_set_dst( conn->c_sb, &op->o_clientaddr );
393                 Debug( LDAP_DEBUG_TRACE, "UDP response to %s port %d\n", 
394                     inet_ntoa(((struct sockaddr_in *)
395                     &op->o_clientaddr)->sin_addr ),
396                     ((struct sockaddr_in *) &op->o_clientaddr)->sin_port,
397                     0 );
398         }
399 #endif
400
401         send_ldap_response( conn, op, tag, msgid,
402                 err, matched, text, ref,
403                 NULL, NULL, ctrls );
404
405         Statslog( LDAP_DEBUG_STATS,
406             "conn=%ld op=%ld RESULT err=%ld tag=%lu text=%s\n",
407                 (long) op->o_connid, (long) op->o_opid,
408                 (long) err, (long) tag, text );
409
410         if( tmp != NULL ) {
411                 free(tmp);
412         }
413 }
414
415
416 void
417 send_search_result(
418     Connection  *conn,
419     Operation   *op,
420     ber_int_t   err,
421     char        *matched,
422         char    *text,
423     struct berval **refs,
424         LDAPControl **ctrls,
425     int         nentries
426 )
427 {
428         ber_tag_t tag;
429         ber_int_t msgid;
430         char *tmp = NULL;
431         assert( !LDAP_API_ERROR( err ) );
432
433         Debug( LDAP_DEBUG_TRACE, "send_ldap_search_result %d:%s:%s\n",
434                 err, matched ?  matched : "", text ? text : "" );
435
436         assert( err != LDAP_PARTIAL_RESULTS );
437
438         trim_refs_urls( refs );
439
440         if( op->o_protocol < LDAP_VERSION3 ) {
441                 /* send references in search results */
442                 if( err == LDAP_REFERRAL ) {
443                         err = LDAP_PARTIAL_RESULTS;
444                 }
445
446                 tmp = text = v2ref( refs );
447                 refs = NULL;
448
449         } else {
450                 /* don't send references in search results */
451                 assert( refs == NULL );
452                 refs = NULL;
453
454                 if( err == LDAP_REFERRAL ) {
455                         err = LDAP_SUCCESS;
456                 }
457         }
458
459         tag = req2res( op->o_tag );
460         msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
461
462 #ifdef LDAP_CONNECTIONLESS
463         if ( op->o_cldap ) {
464                 ber_pvt_sb_udp_set_dst( &conn->c_sb, &op->o_clientaddr );
465                 Debug( LDAP_DEBUG_TRACE, "UDP response to %s port %d\n", 
466                     inet_ntoa(((struct sockaddr_in *)
467                     &op->o_clientaddr)->sin_addr ),
468                     ((struct sockaddr_in *) &op->o_clientaddr)->sin_port,
469                     0 );
470         }
471 #endif
472
473         send_ldap_response( conn, op, tag, msgid,
474                 err, matched, text, refs,
475                 NULL, NULL, ctrls );
476
477         Statslog( LDAP_DEBUG_STATS,
478             "conn=%ld op=%ld SEARCH RESULT err=%ld tag=%lu text=%s\n",
479                 (long) op->o_connid, (long) op->o_opid,
480                 (long) err, (long) tag, text );
481
482 }
483
484
485 int
486 send_search_entry(
487     Backend     *be,
488     Connection  *conn,
489     Operation   *op,
490     Entry       *e,
491     char        **attrs,
492     int         attrsonly,
493         int             opattrs,
494         LDAPControl **ctrls
495 )
496 {
497         BerElement      *ber;
498         Attribute       *a;
499         int             i, rc=-1, bytes;
500         AccessControl   *acl;
501         char            *edn;
502         int             allattrs;
503
504         Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
505
506 #if defined( SLAPD_SCHEMA_DN )
507         {
508                 /* this could be backend specific */
509                 struct  berval  val;
510                 val.bv_val = SLAPD_SCHEMA_DN;
511                 val.bv_len = strlen( val.bv_val );
512                 attr_merge( e, "subschemaSubentry", vals );
513                 ldap_memfree( val.bv_val );
514         }
515 #endif
516
517         if ( ! access_allowed( be, conn, op, e,
518                 "entry", NULL, ACL_READ ) )
519         {
520                 Debug( LDAP_DEBUG_ACL, "acl: access to entry not allowed\n",
521                     0, 0, 0 );
522                 return( 1 );
523         }
524
525         edn = e->e_ndn;
526
527         ber = ber_alloc_t( LBER_USE_DER );
528
529         if ( ber == NULL ) {
530                 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
531                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
532                         NULL, "allocating BER error", NULL, NULL );
533                 goto error_return;
534         }
535
536         rc = ber_printf( ber, "{it{s{", op->o_msgid,
537                 LDAP_RES_SEARCH_ENTRY, e->e_dn );
538
539         if ( rc == -1 ) {
540                 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
541                 ber_free( ber, 1 );
542                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
543                     NULL, "encoding dn error", NULL, NULL );
544                 goto error_return;
545         }
546
547         /* check for special all user attributes ("*") attribute */
548         allattrs = attrs == NULL
549                 ? 1
550                 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
551
552         for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
553                 regmatch_t       matches[MAXREMATCHES];
554
555                 if ( attrs == NULL ) {
556                         /* all addrs request, skip operational attributes */
557                         if( !opattrs && oc_check_operational_attr( a->a_type ) ) {
558                                 continue;
559                         }
560
561                 } else {
562                         /* specific addrs requested */
563                         if ( !allattrs && !charray_inlist( attrs, a->a_type ) ) {
564                                 continue;
565                         }
566                 }
567
568                 acl = acl_get_applicable( be, op, e, a->a_type,
569                         MAXREMATCHES, matches );
570
571                 if ( ! acl_access_allowed( acl, be, conn, e,
572                         NULL, op, ACL_READ, edn, matches ) ) 
573                 {
574                         continue;
575                 }
576
577                 if (( rc = ber_printf( ber, "{s[" /*]}*/ , a->a_type )) == -1 ) {
578                         Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
579                         ber_free( ber, 1 );
580                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
581                             NULL, "encoding type error", NULL, NULL );
582                         goto error_return;
583                 }
584
585                 if ( ! attrsonly ) {
586                         for ( i = 0; a->a_vals[i] != NULL; i++ ) {
587                                 if ( a->a_syntax & SYNTAX_DN && 
588                                         ! acl_access_allowed( acl, be, conn, e, a->a_vals[i], op,
589                                                 ACL_READ, edn, matches) )
590                                 {
591                                         continue;
592                                 }
593
594                                 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
595                                         Debug( LDAP_DEBUG_ANY,
596                                             "ber_printf failed\n", 0, 0, 0 );
597                                         ber_free( ber, 1 );
598                                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
599                                                 NULL, "encoding value error", NULL, NULL );
600                                         goto error_return;
601                                 }
602                         }
603                 }
604
605                 if (( rc = ber_printf( ber, /*{[*/ "]}" )) == -1 ) {
606                         Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
607                         ber_free( ber, 1 );
608                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
609                             NULL, "encode end error", NULL, NULL );
610                         goto error_return;
611                 }
612         }
613
614         rc = ber_printf( ber, /*{{{*/ "}}}" );
615
616         if ( rc == -1 ) {
617                 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
618                 ber_free( ber, 1 );
619                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
620                         NULL, "encode entry end error", NULL, NULL );
621                 return( 1 );
622         }
623
624         bytes = send_ldap_ber( conn, ber );
625
626         if ( bytes < 0 ) {
627                 Debug( LDAP_DEBUG_ANY,
628                         "send_ldap_response: ber write failed\n",
629                         0, 0, 0 );
630                 return -1;
631         }
632
633         ldap_pvt_thread_mutex_lock( &num_sent_mutex );
634         num_bytes_sent += bytes;
635         num_entries_sent++;
636         num_pdu_sent++;
637         ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
638
639         Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
640             (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
641
642         Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
643
644         rc = 0;
645
646 error_return:;
647         return( rc );
648 }
649
650 int
651 send_search_reference(
652     Backend     *be,
653     Connection  *conn,
654     Operation   *op,
655     Entry       *e,
656         struct berval **refs,
657         int scope,
658         LDAPControl **ctrls,
659     struct berval ***v2refs
660 )
661 {
662         BerElement      *ber;
663         int rc;
664         int bytes;
665
666         Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
667
668         if ( ! access_allowed( be, conn, op, e,
669                 "entry", NULL, ACL_READ ) )
670         {
671                 Debug( LDAP_DEBUG_ACL,
672                         "send_search_reference: access to entry not allowed\n",
673                     0, 0, 0 );
674                 return( 1 );
675         }
676
677         if ( ! access_allowed( be, conn, op, e,
678                 "ref", NULL, ACL_READ ) )
679         {
680                 Debug( LDAP_DEBUG_ACL,
681                         "send_search_reference: access to reference not allowed\n",
682                     0, 0, 0 );
683                 return( 1 );
684         }
685
686         if( refs == NULL ) {
687                 Debug( LDAP_DEBUG_ANY,
688                         "send_search_reference: null ref in (%s)\n", 
689                         e->e_dn, 0, 0 );
690                 return( 1 );
691         }
692
693         if( op->o_protocol < LDAP_VERSION3 ) {
694                 /* save the references for the result */
695                 if( *refs == NULL ) {
696                         value_add( v2refs, refs );
697                 }
698                 return 0;
699         }
700
701         ber = ber_alloc_t( LBER_USE_DER );
702
703         if ( ber == NULL ) {
704                 Debug( LDAP_DEBUG_ANY,
705                         "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
706                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
707                         NULL, "alloc BER error", NULL, NULL );
708                 return -1;
709         }
710
711         rc = ber_printf( ber, "{it{V}}", op->o_msgid,
712                 LDAP_RES_SEARCH_REFERENCE, refs );
713
714         if ( rc == -1 ) {
715                 Debug( LDAP_DEBUG_ANY,
716                         "send_search_reference: ber_printf failed\n", 0, 0, 0 );
717                 ber_free( ber, 1 );
718                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
719                         NULL, "encode dn error", NULL, NULL );
720                 return -1;
721         }
722
723         bytes = send_ldap_ber( conn, ber );
724
725         ldap_pvt_thread_mutex_lock( &num_sent_mutex );
726         num_bytes_sent += bytes;
727         num_refs_sent++;
728         num_pdu_sent++;
729         ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
730
731         Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
732             (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
733
734         Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
735
736         return 0;
737 }
738
739
740 int
741 str2result(
742     char        *s,
743     int         *code,
744     char        **matched,
745     char        **info
746 )
747 {
748         int     rc;
749         char    *c;
750
751         *code = LDAP_SUCCESS;
752         *matched = NULL;
753         *info = NULL;
754
755         if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
756                 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
757                     s, 0, 0 );
758
759                 return( -1 );
760         }
761
762         rc = 0;
763         while ( (s = strchr( s, '\n' )) != NULL ) {
764                 *s++ = '\0';
765                 if ( *s == '\0' ) {
766                         break;
767                 }
768                 if ( (c = strchr( s, ':' )) != NULL ) {
769                         c++;
770                 }
771
772                 if ( strncasecmp( s, "code", 4 ) == 0 ) {
773                         if ( c != NULL ) {
774                                 *code = atoi( c );
775                         }
776                 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
777                         if ( c != NULL ) {
778                                 *matched = c;
779                         }
780                 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
781                         if ( c != NULL ) {
782                                 *info = c;
783                         }
784                 } else {
785                         Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
786                             s, 0, 0 );
787                         rc = -1;
788                 }
789         }
790
791         return( rc );
792 }