| 1 |
/* compare.c - sock backend compare function */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 1998-2024 The OpenLDAP Foundation. |
| 6 |
* All rights reserved. |
| 7 |
* |
| 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. |
| 11 |
* |
| 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>. |
| 15 |
*/ |
| 16 |
/* ACKNOWLEDGEMENTS: |
| 17 |
* This work was initially developed by Brian Candler for inclusion |
| 18 |
* in OpenLDAP Software. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "portable.h" |
| 22 |
|
| 23 |
#include <stdio.h> |
| 24 |
|
| 25 |
#include <ac/string.h> |
| 26 |
#include <ac/socket.h> |
| 27 |
|
| 28 |
#include "slap.h" |
| 29 |
#include "back-sock.h" |
| 30 |
#include "ldif.h" |
| 31 |
|
| 32 |
int |
| 33 |
sock_back_compare( |
| 34 |
Operation *op, |
| 35 |
SlapReply *rs ) |
| 36 |
{ |
| 37 |
struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private; |
| 38 |
AttributeDescription *entry = slap_schema.si_ad_entry; |
| 39 |
Entry e; |
| 40 |
FILE *fp; |
| 41 |
char *text; |
| 42 |
|
| 43 |
e.e_id = NOID; |
| 44 |
e.e_name = op->o_req_dn; |
| 45 |
e.e_nname = op->o_req_ndn; |
| 46 |
e.e_attrs = NULL; |
| 47 |
e.e_ocflags = 0; |
| 48 |
e.e_bv.bv_len = 0; |
| 49 |
e.e_bv.bv_val = NULL; |
| 50 |
e.e_private = NULL; |
| 51 |
|
| 52 |
if ( ! access_allowed( op, &e, |
| 53 |
entry, NULL, ACL_COMPARE, NULL ) ) |
| 54 |
{ |
| 55 |
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL ); |
| 56 |
return -1; |
| 57 |
} |
| 58 |
|
| 59 |
if ( (fp = opensock( si->si_sockpath )) == NULL ) { |
| 60 |
send_ldap_error( op, rs, LDAP_OTHER, |
| 61 |
"could not open socket" ); |
| 62 |
return( -1 ); |
| 63 |
} |
| 64 |
|
| 65 |
/* write out the request to the compare process */ |
| 66 |
fprintf( fp, "COMPARE\n" ); |
| 67 |
fprintf( fp, "msgid: %ld\n", (long) op->o_msgid ); |
| 68 |
sock_print_conn( fp, op->o_conn, si ); |
| 69 |
sock_print_suffixes( fp, op->o_bd ); |
| 70 |
fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val ); |
| 71 |
/* could be binary */ |
| 72 |
text = ldif_put_wrap( LDIF_PUT_VALUE, |
| 73 |
op->orc_ava->aa_desc->ad_cname.bv_val, |
| 74 |
op->orc_ava->aa_value.bv_val, |
| 75 |
op->orc_ava->aa_value.bv_len, LDIF_LINE_WIDTH_MAX ); |
| 76 |
if ( text ) { |
| 77 |
fprintf( fp, "%s\n", text ); |
| 78 |
ber_memfree( text ); |
| 79 |
} else { |
| 80 |
fprintf( fp, "\n\n" ); |
| 81 |
} |
| 82 |
|
| 83 |
/* read in the result and send it along */ |
| 84 |
sock_read_and_send_results( op, rs, fp ); |
| 85 |
|
| 86 |
fclose( fp ); |
| 87 |
return( 0 ); |
| 88 |
} |