Back to index

openldap  2.4.31
search.c
Go to the documentation of this file.
00001 /* search.c - shell backend search 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 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
00017  * All rights reserved.
00018  *
00019  * Redistribution and use in source and binary forms are permitted
00020  * provided that this notice is preserved and that due credit is given
00021  * to the University of Michigan at Ann Arbor. The name of the University
00022  * may not be used to endorse or promote products derived from this
00023  * software without specific prior written permission. This software
00024  * is provided ``as is'' without express or implied warranty.
00025  */
00026 /* ACKNOWLEDGEMENTS:
00027  * This work was originally developed by the University of Michigan
00028  * (as part of U-MICH LDAP).
00029  */
00030 
00031 #include "portable.h"
00032 
00033 #include <stdio.h>
00034 
00035 #include <ac/socket.h>
00036 #include <ac/string.h>
00037 
00038 #include "slap.h"
00039 #include "shell.h"
00040 
00041 int
00042 shell_back_search(
00043     Operation *op,
00044     SlapReply *rs )
00045 {
00046        struct shellinfo     *si = (struct shellinfo *) op->o_bd->be_private;
00047        FILE                 *rfp, *wfp;
00048        AttributeName        *an;
00049 
00050        if ( si->si_search == NULL ) {
00051               send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
00052                   "search not implemented" );
00053               return( -1 );
00054        }
00055 
00056        if ( forkandexec( si->si_search, &rfp, &wfp ) == (pid_t)-1 ) {
00057               send_ldap_error( op, rs, LDAP_OTHER,
00058                   "could not fork/exec" );
00059               return( -1 );
00060        }
00061 
00062        /* write out the request to the search process */
00063        fprintf( wfp, "SEARCH\n" );
00064        fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
00065        print_suffixes( wfp, op->o_bd );
00066        fprintf( wfp, "base: %s\n", op->o_req_dn.bv_val );
00067        fprintf( wfp, "scope: %d\n", op->oq_search.rs_scope );
00068        fprintf( wfp, "deref: %d\n", op->oq_search.rs_deref );
00069        fprintf( wfp, "sizelimit: %d\n", op->oq_search.rs_slimit );
00070        fprintf( wfp, "timelimit: %d\n", op->oq_search.rs_tlimit );
00071        fprintf( wfp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
00072        fprintf( wfp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
00073        fprintf( wfp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
00074        for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
00075               fprintf( wfp, " %s", an->an_name.bv_val );
00076        }
00077        fprintf( wfp, "\n" );
00078        fclose( wfp );
00079 
00080        /* read in the results and send them along */
00081        rs->sr_attrs = op->oq_search.rs_attrs;
00082        read_and_send_results( op, rs, rfp );
00083 
00084        fclose( rfp );
00085        return( 0 );
00086 }