]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
merged with autoconf branch
[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 extern Entry    *str2entry();
14
15 void
16 shell_back_search(
17     Backend     *be,
18     Connection  *conn,
19     Operation   *op,
20     char        *base,
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, rc, bsize, len;
33         int                     err;
34         char                    *matched, *info;
35         FILE                    *rfp, *wfp;
36
37         if ( si->si_search == NULL ) {
38                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
39                     "search not implemented" );
40                 return;
41         }
42
43         if ( (op->o_private = forkandexec( si->si_search, &rfp, &wfp ))
44             == -1 ) {
45                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
46                     "could not fork/exec" );
47                 return;
48         }
49
50         /* write out the request to the search process */
51         fprintf( wfp, "SEARCH\n" );
52         fprintf( wfp, "msgid: %d\n", op->o_msgid );
53         print_suffixes( wfp, be );
54         fprintf( wfp, "base: %s\n", base );
55         fprintf( wfp, "scope: %d\n", scope );
56         fprintf( wfp, "deref: %d\n", deref );
57         fprintf( wfp, "sizelimit: %d\n", size );
58         fprintf( wfp, "timelimit: %d\n", time );
59         fprintf( wfp, "filter: %s\n", filterstr );
60         fprintf( wfp, "attrsonly: %d\n", attrsonly ? 1 : 0 );
61         fprintf( wfp, "attrs:%s", attrs == NULL ? " all" : "" );
62         for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
63                 fprintf( wfp, " %s", attrs[i] );
64         }
65         fprintf( wfp, "\n" );
66         fclose( wfp );
67
68         /* read in the results and send them along */
69         read_and_send_results( be, conn, op, rfp, attrs, attrsonly );
70
71         fclose( rfp );
72 }