1 /* $NetBSD: search.c,v 1.3 2021/08/14 16:15:01 christos Exp $ */
2
3 /* search.c - sock backend search function */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2007-2021 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 <sys/cdefs.h>
24 __RCSID("$NetBSD: search.c,v 1.3 2021/08/14 16:15:01 christos Exp $");
25
26 #include "portable.h"
27
28 #include <stdio.h>
29
30 #include <ac/socket.h>
31 #include <ac/string.h>
32
33 #include "slap.h"
34 #include "back-sock.h"
35
36 /*
37 * FIXME: add a filterSearchResults option like back-perl has
38 */
39
40 int
sock_back_search(Operation * op,SlapReply * rs)41 sock_back_search(
42 Operation *op,
43 SlapReply *rs )
44 {
45 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
46 FILE *fp;
47 AttributeName *an;
48
49 if ( (fp = opensock( si->si_sockpath )) == NULL ) {
50 send_ldap_error( op, rs, LDAP_OTHER,
51 "could not open socket" );
52 return( -1 );
53 }
54
55 /* write out the request to the search process */
56 fprintf( fp, "SEARCH\n" );
57 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
58 sock_print_conn( fp, op->o_conn, si );
59 sock_print_suffixes( fp, op->o_bd );
60 fprintf( fp, "base: %s\n", op->o_req_dn.bv_val );
61 fprintf( fp, "scope: %d\n", op->oq_search.rs_scope );
62 fprintf( fp, "deref: %d\n", op->oq_search.rs_deref );
63 fprintf( fp, "sizelimit: %d\n", op->oq_search.rs_slimit );
64 fprintf( fp, "timelimit: %d\n", op->oq_search.rs_tlimit );
65 fprintf( fp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
66 fprintf( fp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
67 fprintf( fp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
68 for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
69 fprintf( fp, " %s", an->an_name.bv_val );
70 }
71 fprintf( fp, "\n\n" ); /* end of attr line plus blank line */
72
73 /* read in the results and send them along */
74 rs->sr_attrs = op->oq_search.rs_attrs;
75 sock_read_and_send_results( op, rs, fp );
76
77 fclose( fp );
78 return( 0 );
79 }
80