Back to index

openldap  2.4.31
search.c
Go to the documentation of this file.
00001 /* search.c - sock backend search function */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2007-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/socket.h>
00026 #include <ac/string.h>
00027 
00028 #include "slap.h"
00029 #include "back-sock.h"
00030 
00031 /*
00032  * FIXME: add a filterSearchResults option like back-perl has
00033  */
00034 
00035 int
00036 sock_back_search(
00037     Operation *op,
00038     SlapReply *rs )
00039 {
00040        struct sockinfo      *si = (struct sockinfo *) op->o_bd->be_private;
00041        FILE                 *fp;
00042        AttributeName        *an;
00043 
00044        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
00045               send_ldap_error( op, rs, LDAP_OTHER,
00046                   "could not open socket" );
00047               return( -1 );
00048        }
00049 
00050        /* write out the request to the search process */
00051        fprintf( fp, "SEARCH\n" );
00052        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
00053        sock_print_conn( fp, op->o_conn, si );
00054        sock_print_suffixes( fp, op->o_bd );
00055        fprintf( fp, "base: %s\n", op->o_req_dn.bv_val );
00056        fprintf( fp, "scope: %d\n", op->oq_search.rs_scope );
00057        fprintf( fp, "deref: %d\n", op->oq_search.rs_deref );
00058        fprintf( fp, "sizelimit: %d\n", op->oq_search.rs_slimit );
00059        fprintf( fp, "timelimit: %d\n", op->oq_search.rs_tlimit );
00060        fprintf( fp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
00061        fprintf( fp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
00062        fprintf( fp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
00063        for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
00064               fprintf( fp, " %s", an->an_name.bv_val );
00065        }
00066        fprintf( fp, "\n\n" );  /* end of attr line plus blank line */
00067 
00068        /* read in the results and send them along */
00069        rs->sr_attrs = op->oq_search.rs_attrs;
00070        sock_read_and_send_results( op, rs, fp );
00071 
00072        fclose( fp );
00073        return( 0 );
00074 }