]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/compare.c
09ffb4d4aa937c0b3c17ba518158d47c74873c2d
[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     Operation   *op,
21     SlapReply   *rs )
22 {
23         struct shellinfo        *si = (struct shellinfo *) op->o_bd->be_private;
24         AttributeDescription *entry = slap_schema.si_ad_entry;
25         Entry e;
26         FILE                    *rfp, *wfp;
27
28         if ( si->si_compare == NULL ) {
29                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
30                     "compare not implemented" );
31                 return( -1 );
32         }
33
34         e.e_id = NOID;
35         e.e_name = op->o_req_dn;
36         e.e_nname = op->o_req_ndn;
37         e.e_attrs = NULL;
38         e.e_ocflags = 0;
39         e.e_bv.bv_len = 0;
40         e.e_bv.bv_val = NULL;
41         e.e_private = NULL;
42
43         if ( ! access_allowed( op, &e,
44                 entry, NULL, ACL_READ, NULL ) )
45         {
46                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
47                 return -1;
48         }
49
50         if ( (op->o_private = (void *) forkandexec( si->si_compare, &rfp, &wfp ))
51             == (void *) -1 ) {
52                 send_ldap_error( op, rs, LDAP_OTHER,
53                     "could not fork/exec" );
54                 return( -1 );
55         }
56
57         /*
58          * FIX ME:  This should use LDIF routines so that binary
59          *      values are properly dealt with
60          */
61
62         /* write out the request to the compare process */
63         fprintf( wfp, "COMPARE\n" );
64         fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
65         print_suffixes( wfp, op->o_bd );
66         fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
67         fprintf( wfp, "%s: %s\n",
68                 op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val,
69                 op->oq_compare.rs_ava->aa_value.bv_val /* could be binary! */ );
70         fclose( wfp );
71
72         /* read in the result and send it along */
73         read_and_send_results( op, rs, rfp );
74
75         fclose( rfp );
76         return( 0 );
77 }