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