]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
Do not return pointers into BerElement we do not own
[openldap] / servers / slapd / back-shell / search.c
1 /* search.c - shell backend search function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/socket.h>
13 #include <ac/string.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 int
19 shell_back_search(
20     Operation   *op,
21     SlapReply   *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         FILE                    *rfp, *wfp;
25         AttributeName           *an;
26
27         if ( si->si_search == NULL ) {
28                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
29                     "search not implemented" );
30                 return( -1 );
31         }
32
33         if ( (op->o_private = (void *) forkandexec( si->si_search, &rfp, &wfp ))
34             == (void *) -1 ) {
35                 send_ldap_error( op, rs, LDAP_OTHER,
36                     "could not fork/exec" );
37                 return( -1 );
38         }
39
40         /* write out the request to the search process */
41         fprintf( wfp, "SEARCH\n" );
42         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
43         print_suffixes( wfp, op->o_bd );
44         fprintf( wfp, "base: %s\n", op->o_req_dn.bv_val );
45         fprintf( wfp, "scope: %d\n", op->oq_search.rs_scope );
46         fprintf( wfp, "deref: %d\n", op->oq_search.rs_deref );
47         fprintf( wfp, "sizelimit: %d\n", op->oq_search.rs_slimit );
48         fprintf( wfp, "timelimit: %d\n", op->oq_search.rs_tlimit );
49         fprintf( wfp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
50         fprintf( wfp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
51         fprintf( wfp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
52         for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
53                 fprintf( wfp, " %s", an->an_name.bv_val );
54         }
55         fprintf( wfp, "\n" );
56         fclose( wfp );
57
58         /* read in the results and send them along */
59         rs->sr_attrs = op->oq_search.rs_attrs;
60         read_and_send_results( op, rs, rfp );
61
62         fclose( rfp );
63         return( 0 );
64 }