]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
Import slapd nextid chunking from -devel.
[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, rc, bsize, len;
31         int                     err;
32         char                    *matched, *info;
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" );
38                 return( -1 );
39         }
40
41         if ( (op->o_private = forkandexec( si->si_search, &rfp, &wfp ))
42             == -1 ) {
43                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
44                     "could not fork/exec" );
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", 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 }