]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
Per ITS#419, don't require SLAPD_RLOOKUPS when HAVE_TCPD
[openldap] / servers / slapd / back-shell / search.c
1 /* search.c - shell backend search function */
2 /* $OpenLDAP$ */
3
4 #include "portable.h"
5
6 #include <stdio.h>
7
8 #include <ac/socket.h>
9 #include <ac/string.h>
10
11 #include "slap.h"
12 #include "shell.h"
13
14 int
15 shell_back_search(
16     Backend     *be,
17     Connection  *conn,
18     Operation   *op,
19     char        *base,
20     char        *nbase,
21     int         scope,
22     int         deref,
23     int         size,
24     int         time,
25     Filter      *filter,
26     char        *filterstr,
27     char        **attrs,
28     int         attrsonly
29 )
30 {
31         struct shellinfo        *si = (struct shellinfo *) be->be_private;
32         int                     i;
33         FILE                    *rfp, *wfp;
34
35         if ( si->si_search == NULL ) {
36                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
37                     "search not implemented", NULL, NULL );
38                 return( -1 );
39         }
40
41         if ( (op->o_private = (void *) forkandexec( si->si_search, &rfp, &wfp ))
42             == (void *) -1 ) {
43                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
44                     "could not fork/exec", NULL, NULL );
45                 return( -1 );
46         }
47
48         /* write out the request to the search process */
49         fprintf( wfp, "SEARCH\n" );
50         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
51         print_suffixes( wfp, be );
52         fprintf( wfp, "base: %s\n", base );
53         fprintf( wfp, "scope: %d\n", scope );
54         fprintf( wfp, "deref: %d\n", deref );
55         fprintf( wfp, "sizelimit: %d\n", size );
56         fprintf( wfp, "timelimit: %d\n", time );
57         fprintf( wfp, "filter: %s\n", filterstr );
58         fprintf( wfp, "attrsonly: %d\n", attrsonly ? 1 : 0 );
59         fprintf( wfp, "attrs:%s", attrs == NULL ? " all" : "" );
60         for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
61                 fprintf( wfp, " %s", attrs[i] );
62         }
63         fprintf( wfp, "\n" );
64         fclose( wfp );
65
66         /* read in the results and send them along */
67         read_and_send_results( be, conn, op, rfp, attrs, attrsonly );
68
69         fclose( rfp );
70         return( 0 );
71 }