Back to index

openldap  2.4.31
compare.c
Go to the documentation of this file.
00001 /* compare.c - sock backend compare function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Brian Candler for inclusion
00018  * in OpenLDAP Software.
00019  */
00020 
00021 #include "portable.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include <ac/string.h>
00026 #include <ac/socket.h>
00027 
00028 #include "slap.h"
00029 #include "back-sock.h"
00030 #include "ldif.h"
00031 
00032 int
00033 sock_back_compare(
00034     Operation *op,
00035     SlapReply *rs )
00036 {
00037        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00038        AttributeDescription *entry = slap_schema.si_ad_entry;
00039        Entry e;
00040        FILE                 *fp;
00041        char *text;
00042 
00043        e.e_id = NOID;
00044        e.e_name = op->o_req_dn;
00045        e.e_nname = op->o_req_ndn;
00046        e.e_attrs = NULL;
00047        e.e_ocflags = 0;
00048        e.e_bv.bv_len = 0;
00049        e.e_bv.bv_val = NULL;
00050        e.e_private = NULL;
00051 
00052        if ( ! access_allowed( op, &e,
00053               entry, NULL, ACL_COMPARE, NULL ) )
00054        {
00055               send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
00056               return -1;
00057        }
00058 
00059        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00060               send_ldap_error( op, rs, LDAP_OTHER,
00061                   "could not open socket" );
00062               return( -1 );
00063        }
00064 
00065        /* write out the request to the compare process */
00066        fprintf( fp, "COMPARE\n" );
00067        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00068        sock_print_conn( fp, op->o_conn, si );
00069        sock_print_suffixes( fp, op->o_bd );
00070        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
00071        /* could be binary */
00072        text = ldif_put_wrap( LDIF_PUT_VALUE,
00073               op->orc_ava->aa_desc->ad_cname.bv_val,
00074               op->orc_ava->aa_value.bv_val,
00075               op->orc_ava->aa_value.bv_len, LDIF_LINE_WIDTH_MAX );
00076        if ( text ) {
00077               fprintf( fp, "%s\n", text );
00078               ber_memfree( text );
00079        } else {
00080               fprintf( fp, "\n\n" );
00081        }
00082 
00083        /* read in the result and send it along */
00084        sock_read_and_send_results( op, rs, fp );
00085 
00086        fclose( fp );
00087        return( 0 );
00088 }