]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/compare.c
Commit of the Proxy Cache contribution (ITS#2062)
[openldap] / servers / slapd / back-shell / compare.c
1 /* compare.c - shell backend compare function */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 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/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "shell.h"
17
18 int
19 shell_back_compare(
20     Backend     *be,
21     Connection  *conn,
22     Operation   *op,
23     struct berval *dn,
24     struct berval *ndn,
25     AttributeAssertion *ava
26 )
27 {
28         struct shellinfo        *si = (struct shellinfo *) be->be_private;
29         AttributeDescription *entry = slap_schema.si_ad_entry;
30         Entry e;
31         FILE                    *rfp, *wfp;
32
33         if ( si->si_compare == NULL ) {
34                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
35                     "compare not implemented", NULL, NULL );
36                 return( -1 );
37         }
38
39         e.e_id = NOID;
40         e.e_name = *dn;
41         e.e_nname = *ndn;
42         e.e_attrs = NULL;
43         e.e_ocflags = 0;
44         e.e_bv.bv_len = 0;
45         e.e_bv.bv_val = NULL;
46         e.e_private = NULL;
47
48         if ( ! access_allowed( be, conn, op, &e,
49                 entry, NULL, ACL_READ, NULL ) )
50         {
51                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
52                         NULL, NULL, NULL, NULL );
53                 return -1;
54         }
55
56         if ( (op->o_private = (void *) forkandexec( si->si_compare, &rfp, &wfp ))
57             == (void *) -1 ) {
58                 send_ldap_result( conn, op, LDAP_OTHER, NULL,
59                     "could not fork/exec", NULL, NULL );
60                 return( -1 );
61         }
62
63         /*
64          * FIX ME:  This should use LDIF routines so that binary
65          *      values are properly dealt with
66          */
67
68         /* write out the request to the compare process */
69         fprintf( wfp, "COMPARE\n" );
70         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
71         print_suffixes( wfp, be );
72         fprintf( wfp, "dn: %s\n", dn->bv_val );
73         fprintf( wfp, "%s: %s\n",
74                 ava->aa_desc->ad_cname.bv_val,
75                 ava->aa_value.bv_val /* could be binary! */ );
76         fclose( wfp );
77
78         /* read in the result and send it along */
79         read_and_send_results( be, conn, op, rfp, NULL, 0 );
80
81         fclose( rfp );
82         return( 0 );
83 }