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