]> git.sur5r.net Git - openldap/blob - servers/slapd/str2filter.c
Happy New Year
[openldap] / servers / slapd / str2filter.c
1 /* str2filter.c - parse an RFC 4515 string filter */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2018 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26
27 #include "portable.h"
28
29 #include <stdio.h>
30
31 #include <ac/string.h>
32 #include <ac/ctype.h>
33 #include <ac/socket.h>
34
35 #include "slap.h"
36
37
38 Filter *
39 str2filter_x( Operation *op, const char *str )
40 {
41         int rc;
42         Filter  *f = NULL;
43         BerElementBuffer berbuf;
44         BerElement *ber = (BerElement *)&berbuf;
45         const char *text = NULL;
46
47         Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
48
49         if ( str == NULL || *str == '\0' ) {
50                 return NULL;
51         }
52
53         ber_init2( ber, NULL, LBER_USE_DER );
54         if ( op->o_tmpmemctx ) {
55                 ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
56         }
57
58         rc = ldap_pvt_put_filter( ber, str );
59         if( rc < 0 ) {
60                 goto done;
61         }
62
63         ber_reset( ber, 1 );
64
65         rc = get_filter( op, ber, &f, &text );
66
67 done:
68         ber_free_buf( ber );
69
70         return f;
71 }
72
73 Filter *
74 str2filter( const char *str )
75 {
76         Operation op = {0};
77         Opheader ohdr = {0};
78
79         op.o_hdr = &ohdr;
80         op.o_tmpmemctx = NULL;
81         op.o_tmpmfuncs = &ch_mfuncs;
82
83         return str2filter_x( &op, str );
84 }