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