]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
b2b6587719ba9fd30fa4fcebb6d4190d7a6da487
[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     int         scope,
21     int         deref,
22     int         size,
23     int         time,
24     Filter      *filter,
25     char        *filterstr,
26     char        **attrs,
27     int         attrsonly
28 )
29 {
30         struct shellinfo        *si = (struct shellinfo *) be->be_private;
31         int                     i;
32         FILE                    *rfp, *wfp;
33
34         if ( si->si_search == NULL ) {
35                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
36                     "search not implemented", NULL, NULL );
37                 return( -1 );
38         }
39
40         if ( (op->o_private = (void *) forkandexec( si->si_search, &rfp, &wfp ))
41             == (void *) -1 ) {
42                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
43                     "could not fork/exec", NULL, NULL );
44                 return( -1 );
45         }
46
47         /* write out the request to the search process */
48         fprintf( wfp, "SEARCH\n" );
49         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
50         print_suffixes( wfp, be );
51         fprintf( wfp, "base: %s\n", base );
52         fprintf( wfp, "scope: %d\n", scope );
53         fprintf( wfp, "deref: %d\n", deref );
54         fprintf( wfp, "sizelimit: %d\n", size );
55         fprintf( wfp, "timelimit: %d\n", time );
56         fprintf( wfp, "filter: %s\n", filterstr );
57         fprintf( wfp, "attrsonly: %d\n", attrsonly ? 1 : 0 );
58         fprintf( wfp, "attrs:%s", attrs == NULL ? " all" : "" );
59         for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
60                 fprintf( wfp, " %s", attrs[i] );
61         }
62         fprintf( wfp, "\n" );
63         fclose( wfp );
64
65         /* read in the results and send them along */
66         read_and_send_results( be, conn, op, rfp, attrs, attrsonly );
67
68         fclose( rfp );
69         return( 0 );
70 }