]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/search.c
Fixed "faled" typo in debug message
[openldap] / servers / slapd / back-shell / search.c
1 /* search.c - shell backend search function */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include "slap.h"
8 #include "shell.h"
9
10 extern Entry    *str2entry();
11
12 void
13 shell_back_search(
14     Backend     *be,
15     Connection  *conn,
16     Operation   *op,
17     char        *base,
18     int         scope,
19     int         deref,
20     int         size,
21     int         time,
22     Filter      *filter,
23     char        *filterstr,
24     char        **attrs,
25     int         attrsonly
26 )
27 {
28         struct shellinfo        *si = (struct shellinfo *) be->be_private;
29         int                     i, rc, bsize, len;
30         int                     err;
31         char                    *matched, *info;
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" );
37                 return;
38         }
39
40         if ( (op->o_private = forkandexec( si->si_search, &rfp, &wfp ))
41             == -1 ) {
42                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
43                     "could not fork/exec" );
44                 return;
45         }
46
47         /* write out the request to the search process */
48         fprintf( wfp, "SEARCH\n" );
49         fprintf( wfp, "msgid: %d\n", 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 }