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