]> git.sur5r.net Git - openldap/blob - servers/slapd/result.c
(re)introduce o_connid such that STATS doesn't need c_mutex (which it
[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                         tmp = text = v2ref( refs );
445                         refs = NULL;
446                 }
447
448         } else {
449                 /* don't send references in search results */
450                 if( err == LDAP_REFERRAL ) {
451                         err = LDAP_SUCCESS;
452                         refs = NULL;
453                 }
454         }
455
456         tag = req2res( op->o_tag );
457         msgid = (tag != LBER_SEQUENCE) ? op->o_msgid : 0;
458
459 #ifdef LDAP_CONNECTIONLESS
460         if ( op->o_cldap ) {
461                 ber_pvt_sb_udp_set_dst( &conn->c_sb, &op->o_clientaddr );
462                 Debug( LDAP_DEBUG_TRACE, "UDP response to %s port %d\n", 
463                     inet_ntoa(((struct sockaddr_in *)
464                     &op->o_clientaddr)->sin_addr ),
465                     ((struct sockaddr_in *) &op->o_clientaddr)->sin_port,
466                     0 );
467         }
468 #endif
469
470         send_ldap_response( conn, op, tag, msgid,
471                 err, matched, text, refs,
472                 NULL, NULL, ctrls );
473
474         Statslog( LDAP_DEBUG_STATS,
475             "conn=%ld op=%ld SEARCH RESULT err=%ld tag=%lu text=%s\n",
476                 (long) op->o_connid, (long) op->o_opid,
477                 (long) err, (long) tag, text );
478
479 }
480
481
482 int
483 send_search_entry(
484     Backend     *be,
485     Connection  *conn,
486     Operation   *op,
487     Entry       *e,
488     char        **attrs,
489     int         attrsonly,
490         int             opattrs,
491         LDAPControl **ctrls
492 )
493 {
494         BerElement      *ber;
495         Attribute       *a;
496         int             i, rc=-1, bytes;
497         struct acl      *acl;
498         char            *edn;
499         int             allattrs;
500
501         Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
502
503 #if defined( SLAPD_SCHEMA_DN )
504         {
505                 /* this could be backend specific */
506                 struct  berval  val;
507                 val.bv_val = SLAPD_SCHEMA_DN;
508                 val.bv_len = strlen( val.bv_val );
509                 attr_merge( e, "subschemaSubentry", vals );
510                 ldap_memfree( val.bv_val );
511         }
512 #endif
513
514         if ( ! access_allowed( be, conn, op, e,
515                 "entry", NULL, ACL_READ ) )
516         {
517                 Debug( LDAP_DEBUG_ACL, "acl: access to entry not allowed\n",
518                     0, 0, 0 );
519                 return( 1 );
520         }
521
522         edn = e->e_ndn;
523
524         ber = ber_alloc_t( LBER_USE_DER );
525
526         if ( ber == NULL ) {
527                 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
528                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
529                         NULL, "allocating BER error", NULL, NULL );
530                 goto error_return;
531         }
532
533         rc = ber_printf( ber, "{it{s{", op->o_msgid,
534                 LDAP_RES_SEARCH_ENTRY, e->e_dn );
535
536         if ( rc == -1 ) {
537                 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
538                 ber_free( ber, 1 );
539                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
540                     NULL, "encoding dn error", NULL, NULL );
541                 goto error_return;
542         }
543
544         /* check for special all user attributes ("*") attribute */
545         allattrs = attrs == NULL
546                 ? 1
547                 : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
548
549         for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
550                 regmatch_t       matches[MAXREMATCHES];
551
552                 if ( attrs == NULL ) {
553                         /* all addrs request, skip operational attributes */
554                         if( !opattrs && oc_check_operational_attr( a->a_type ) ) {
555                                 continue;
556                         }
557
558                 } else {
559                         /* specific addrs requested */
560                         if ( !allattrs && !charray_inlist( attrs, a->a_type ) ) {
561                                 continue;
562                         }
563                 }
564
565                 acl = acl_get_applicable( be, op, e, a->a_type,
566                         MAXREMATCHES, matches );
567
568                 if ( ! acl_access_allowed( acl, be, conn, e,
569                         NULL, op, ACL_READ, edn, matches ) ) 
570                 {
571                         continue;
572                 }
573
574                 if (( rc = ber_printf( ber, "{s[" /*]}*/ , a->a_type )) == -1 ) {
575                         Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
576                         ber_free( ber, 1 );
577                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
578                             NULL, "encoding type error", NULL, NULL );
579                         goto error_return;
580                 }
581
582                 if ( ! attrsonly ) {
583                         for ( i = 0; a->a_vals[i] != NULL; i++ ) {
584                                 if ( a->a_syntax & SYNTAX_DN && 
585                                         ! acl_access_allowed( acl, be, conn, e, a->a_vals[i], op,
586                                                 ACL_READ, edn, matches) )
587                                 {
588                                         continue;
589                                 }
590
591                                 if (( rc = ber_printf( ber, "O", a->a_vals[i] )) == -1 ) {
592                                         Debug( LDAP_DEBUG_ANY,
593                                             "ber_printf failed\n", 0, 0, 0 );
594                                         ber_free( ber, 1 );
595                                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
596                                                 NULL, "encoding value error", NULL, NULL );
597                                         goto error_return;
598                                 }
599                         }
600                 }
601
602                 if (( rc = ber_printf( ber, /*{[*/ "]}" )) == -1 ) {
603                         Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
604                         ber_free( ber, 1 );
605                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
606                             NULL, "encode end error", NULL, NULL );
607                         goto error_return;
608                 }
609         }
610
611         rc = ber_printf( ber, /*{{{*/ "}}}" );
612
613         if ( rc == -1 ) {
614                 Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
615                 ber_free( ber, 1 );
616                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
617                         NULL, "encode entry end error", NULL, NULL );
618                 return( 1 );
619         }
620
621         bytes = send_ldap_ber( conn, ber );
622
623         if ( bytes < 0 ) {
624                 Debug( LDAP_DEBUG_ANY,
625                         "send_ldap_response: ber write failed\n",
626                         0, 0, 0 );
627                 return -1;
628         }
629
630         ldap_pvt_thread_mutex_lock( &num_sent_mutex );
631         num_bytes_sent += bytes;
632         num_entries_sent++;
633         num_pdu_sent++;
634         ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
635
636         Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
637             (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
638
639         Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
640
641         rc = 0;
642
643 error_return:;
644         return( rc );
645 }
646
647 int
648 send_search_reference(
649     Backend     *be,
650     Connection  *conn,
651     Operation   *op,
652     Entry       *e,
653         struct berval **refs,
654         int scope,
655         LDAPControl **ctrls,
656     struct berval ***v2refs
657 )
658 {
659         BerElement      *ber;
660         int rc;
661         int bytes;
662
663         Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
664
665         if ( ! access_allowed( be, conn, op, e,
666                 "entry", NULL, ACL_READ ) )
667         {
668                 Debug( LDAP_DEBUG_ACL,
669                         "send_search_reference: access to entry not allowed\n",
670                     0, 0, 0 );
671                 return( 1 );
672         }
673
674         if ( ! access_allowed( be, conn, op, e,
675                 "ref", NULL, ACL_READ ) )
676         {
677                 Debug( LDAP_DEBUG_ACL,
678                         "send_search_reference: access to reference not allowed\n",
679                     0, 0, 0 );
680                 return( 1 );
681         }
682
683         if( refs == NULL ) {
684                 Debug( LDAP_DEBUG_ANY,
685                         "send_search_reference: null ref in (%s)\n", 
686                         e->e_dn, 0, 0 );
687                 return( 1 );
688         }
689
690         if( op->o_protocol < LDAP_VERSION3 ) {
691                 /* save the references for the result */
692                 if( *refs == NULL ) {
693                         value_add( v2refs, refs );
694                 }
695                 return 0;
696         }
697
698         ber = ber_alloc_t( LBER_USE_DER );
699
700         if ( ber == NULL ) {
701                 Debug( LDAP_DEBUG_ANY,
702                         "send_search_reference: ber_alloc failed\n", 0, 0, 0 );
703                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
704                         NULL, "alloc BER error", NULL, NULL );
705                 return -1;
706         }
707
708         rc = ber_printf( ber, "{it{V}}", op->o_msgid,
709                 LDAP_RES_SEARCH_REFERENCE, refs );
710
711         if ( rc == -1 ) {
712                 Debug( LDAP_DEBUG_ANY,
713                         "send_search_reference: ber_printf failed\n", 0, 0, 0 );
714                 ber_free( ber, 1 );
715                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
716                         NULL, "encode dn error", NULL, NULL );
717                 return -1;
718         }
719
720         bytes = send_ldap_ber( conn, ber );
721
722         ldap_pvt_thread_mutex_lock( &num_sent_mutex );
723         num_bytes_sent += bytes;
724         num_refs_sent++;
725         num_pdu_sent++;
726         ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
727
728         Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
729             (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
730
731         Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
732
733         return 0;
734 }
735
736
737 int
738 str2result(
739     char        *s,
740     int         *code,
741     char        **matched,
742     char        **info
743 )
744 {
745         int     rc;
746         char    *c;
747
748         *code = LDAP_SUCCESS;
749         *matched = NULL;
750         *info = NULL;
751
752         if ( strncasecmp( s, "RESULT", 6 ) != 0 ) {
753                 Debug( LDAP_DEBUG_ANY, "str2result (%s) expecting \"RESULT\"\n",
754                     s, 0, 0 );
755
756                 return( -1 );
757         }
758
759         rc = 0;
760         while ( (s = strchr( s, '\n' )) != NULL ) {
761                 *s++ = '\0';
762                 if ( *s == '\0' ) {
763                         break;
764                 }
765                 if ( (c = strchr( s, ':' )) != NULL ) {
766                         c++;
767                 }
768
769                 if ( strncasecmp( s, "code", 4 ) == 0 ) {
770                         if ( c != NULL ) {
771                                 *code = atoi( c );
772                         }
773                 } else if ( strncasecmp( s, "matched", 7 ) == 0 ) {
774                         if ( c != NULL ) {
775                                 *matched = c;
776                         }
777                 } else if ( strncasecmp( s, "info", 4 ) == 0 ) {
778                         if ( c != NULL ) {
779                                 *info = c;
780                         }
781                 } else {
782                         Debug( LDAP_DEBUG_ANY, "str2result (%s) unknown\n",
783                             s, 0, 0 );
784                         rc = -1;
785                 }
786         }
787
788         return( rc );
789 }