search.c revision 1.4 1 1.3 christos /* $NetBSD: search.c,v 1.4 2025/09/05 21:16:31 christos Exp $ */
2 1.2 christos
3 1.1 lukem /* search.c - sock backend search function */
4 1.2 christos /* $OpenLDAP$ */
5 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 1.1 lukem *
7 1.4 christos * Copyright 2007-2024 The OpenLDAP Foundation.
8 1.1 lukem * All rights reserved.
9 1.1 lukem *
10 1.1 lukem * Redistribution and use in source and binary forms, with or without
11 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
12 1.1 lukem * Public License.
13 1.1 lukem *
14 1.1 lukem * A copy of this license is available in the file LICENSE in the
15 1.1 lukem * top-level directory of the distribution or, alternatively, at
16 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
17 1.1 lukem */
18 1.1 lukem /* ACKNOWLEDGEMENTS:
19 1.1 lukem * This work was initially developed by Brian Candler for inclusion
20 1.1 lukem * in OpenLDAP Software.
21 1.1 lukem */
22 1.1 lukem
23 1.2 christos #include <sys/cdefs.h>
24 1.3 christos __RCSID("$NetBSD: search.c,v 1.4 2025/09/05 21:16:31 christos Exp $");
25 1.2 christos
26 1.1 lukem #include "portable.h"
27 1.1 lukem
28 1.1 lukem #include <stdio.h>
29 1.1 lukem
30 1.1 lukem #include <ac/socket.h>
31 1.1 lukem #include <ac/string.h>
32 1.1 lukem
33 1.1 lukem #include "slap.h"
34 1.1 lukem #include "back-sock.h"
35 1.1 lukem
36 1.1 lukem /*
37 1.1 lukem * FIXME: add a filterSearchResults option like back-perl has
38 1.1 lukem */
39 1.1 lukem
40 1.1 lukem int
41 1.1 lukem sock_back_search(
42 1.1 lukem Operation *op,
43 1.1 lukem SlapReply *rs )
44 1.1 lukem {
45 1.1 lukem struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
46 1.1 lukem FILE *fp;
47 1.1 lukem AttributeName *an;
48 1.1 lukem
49 1.1 lukem if ( (fp = opensock( si->si_sockpath )) == NULL ) {
50 1.1 lukem send_ldap_error( op, rs, LDAP_OTHER,
51 1.1 lukem "could not open socket" );
52 1.1 lukem return( -1 );
53 1.1 lukem }
54 1.1 lukem
55 1.1 lukem /* write out the request to the search process */
56 1.1 lukem fprintf( fp, "SEARCH\n" );
57 1.1 lukem fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
58 1.1 lukem sock_print_conn( fp, op->o_conn, si );
59 1.1 lukem sock_print_suffixes( fp, op->o_bd );
60 1.1 lukem fprintf( fp, "base: %s\n", op->o_req_dn.bv_val );
61 1.1 lukem fprintf( fp, "scope: %d\n", op->oq_search.rs_scope );
62 1.1 lukem fprintf( fp, "deref: %d\n", op->oq_search.rs_deref );
63 1.1 lukem fprintf( fp, "sizelimit: %d\n", op->oq_search.rs_slimit );
64 1.1 lukem fprintf( fp, "timelimit: %d\n", op->oq_search.rs_tlimit );
65 1.1 lukem fprintf( fp, "filter: %s\n", op->oq_search.rs_filterstr.bv_val );
66 1.1 lukem fprintf( fp, "attrsonly: %d\n", op->oq_search.rs_attrsonly ? 1 : 0 );
67 1.1 lukem fprintf( fp, "attrs:%s", op->oq_search.rs_attrs == NULL ? " all" : "" );
68 1.1 lukem for ( an = op->oq_search.rs_attrs; an && an->an_name.bv_val; an++ ) {
69 1.1 lukem fprintf( fp, " %s", an->an_name.bv_val );
70 1.1 lukem }
71 1.1 lukem fprintf( fp, "\n\n" ); /* end of attr line plus blank line */
72 1.1 lukem
73 1.1 lukem /* read in the results and send them along */
74 1.1 lukem rs->sr_attrs = op->oq_search.rs_attrs;
75 1.1 lukem sock_read_and_send_results( op, rs, fp );
76 1.1 lukem
77 1.1 lukem fclose( fp );
78 1.1 lukem return( 0 );
79 1.1 lukem }
80