]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
Berkeley DB 4.2 support (DB 4.2 required by default)
[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 ( forkandexec( si->si_search, &rfp, &wfp ) == (pid_t)-1 ) {
34                 send_ldap_error( op, rs, LDAP_OTHER,
35                     "could not fork/exec" );
36                 return( -1 );
37         }
38
39         /* write out the request to the search process */
40         fprintf( wfp, "SEARCH\n" );
41         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
42         print_suffixes( wfp, op->o_bd );
43         fprintf( wfp, "base: %s\n", op->o_req_dn.bv_val );
44         fprintf( wfp, "scope: %d\n", op->oq_search.rs_scope );
45         fprintf( wfp, "deref: %d\n", op->oq_search.rs_deref );
46         fprintf( wfp, "sizelimit: %d\n", op->oq_search.rs_slimit );
47         fprintf( wfp, "timelimit: %d\n", op->oq_search.rs_tlimit );
48         fprintf( wfp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
49         fprintf( wfp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
50         fprintf( wfp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
51         for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
52                 fprintf( wfp, " %s", an->an_name.bv_val );
53         }
54         fprintf( wfp, "\n" );
55         fclose( wfp );
56
57         /* read in the results and send them along */
58         rs->sr_attrs = op->oq_search.rs_attrs;
59         read_and_send_results( op, rs, rfp );
60
61         fclose( rfp );
62         return( 0 );
63 }