]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/compare.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slapd / back-shell / compare.c
1 /* compare.c - shell backend compare function */
2 /* $OpenLDAP$ */
3
4 #include "portable.h"
5
6 #include <stdio.h>
7
8 #include <ac/string.h>
9 #include <ac/socket.h>
10
11 #include "slap.h"
12 #include "shell.h"
13
14 int
15 shell_back_compare(
16     Backend     *be,
17     Connection  *conn,
18     Operation   *op,
19     char        *dn,
20     Ava         *ava
21 )
22 {
23         struct shellinfo        *si = (struct shellinfo *) be->be_private;
24         FILE                    *rfp, *wfp;
25
26         if ( si->si_compare == NULL ) {
27                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
28                     "compare not implemented", NULL, NULL );
29                 return( -1 );
30         }
31
32         if ( (op->o_private = (void *) forkandexec( si->si_compare, &rfp, &wfp ))
33             == (void *) -1 ) {
34                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
35                     "could not fork/exec", NULL, NULL );
36                 return( -1 );
37         }
38
39         /* write out the request to the compare process */
40         fprintf( wfp, "COMPARE\n" );
41         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
42         print_suffixes( wfp, be );
43         fprintf( wfp, "dn: %s\n", dn );
44         fprintf( wfp, "%s: %s\n", ava->ava_type, ava->ava_value.bv_val );
45         fclose( wfp );
46
47         /* read in the result and send it along */
48         read_and_send_results( be, conn, op, rfp, NULL, 0 );
49
50         fclose( rfp );
51         return( 0 );
52 }