Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-shell / compare.c
blob16265ba73cac76890af24636ec7eb5c633d63838
1 /* compare.c - shell backend compare function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-shell/compare.c,v 1.28.2.3 2008/02/11 23:26:47 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
26 /* ACKNOWLEDGEMENTS:
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
31 #include "portable.h"
33 #include <stdio.h>
35 #include <ac/string.h>
36 #include <ac/socket.h>
38 #include "slap.h"
39 #include "shell.h"
41 int
42 shell_back_compare(
43 Operation *op,
44 SlapReply *rs )
46 struct shellinfo *si = (struct shellinfo *) op->o_bd->be_private;
47 AttributeDescription *entry = slap_schema.si_ad_entry;
48 Entry e;
49 FILE *rfp, *wfp;
51 if ( si->si_compare == NULL ) {
52 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
53 "compare not implemented" );
54 return( -1 );
57 e.e_id = NOID;
58 e.e_name = op->o_req_dn;
59 e.e_nname = op->o_req_ndn;
60 e.e_attrs = NULL;
61 e.e_ocflags = 0;
62 e.e_bv.bv_len = 0;
63 e.e_bv.bv_val = NULL;
64 e.e_private = NULL;
66 if ( ! access_allowed( op, &e,
67 entry, NULL, ACL_READ, NULL ) )
69 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
70 return -1;
73 if ( forkandexec( si->si_compare, &rfp, &wfp ) == (pid_t)-1 ) {
74 send_ldap_error( op, rs, LDAP_OTHER,
75 "could not fork/exec" );
76 return( -1 );
80 * FIX ME: This should use LDIF routines so that binary
81 * values are properly dealt with
84 /* write out the request to the compare process */
85 fprintf( wfp, "COMPARE\n" );
86 fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
87 print_suffixes( wfp, op->o_bd );
88 fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
89 fprintf( wfp, "%s: %s\n",
90 op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val,
91 op->oq_compare.rs_ava->aa_value.bv_val /* could be binary! */ );
92 fclose( wfp );
94 /* read in the result and send it along */
95 read_and_send_results( op, rs, rfp );
97 fclose( rfp );
98 return( 0 );