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