str2filter.c 1.96 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
/* str2filter.c - parse an RFC 4515 string filter */
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
4
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
5
 * Copyright 1998-2019 The OpenLDAP Foundation.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
25
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
26

Kurt Zeilenga's avatar
Kurt Zeilenga committed
27
28
#include "portable.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
29
#include <stdio.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
30
31

#include <ac/string.h>
32
#include <ac/ctype.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
33
34
#include <ac/socket.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
35
36
37
38
#include "slap.h"


Filter *
39
str2filter_x( Operation *op, const char *str )
Kurt Zeilenga's avatar
Kurt Zeilenga committed
40
{
41
	int rc;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
42
	Filter	*f = NULL;
43
44
	BerElementBuffer berbuf;
	BerElement *ber = (BerElement *)&berbuf;
45
	const char *text = NULL;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
46
47

	Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
48

Kurt Zeilenga's avatar
Kurt Zeilenga committed
49
	if ( str == NULL || *str == '\0' ) {
50
		return NULL;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
51
52
	}

Howard Chu's avatar
Howard Chu committed
53
	ber_init2( ber, NULL, LBER_USE_DER );
54
	if ( op->o_tmpmemctx ) {
Howard Chu's avatar
Howard Chu committed
55
		ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
56
	}
57

58
	rc = ldap_pvt_put_filter( ber, str );
59
60
	if( rc < 0 ) {
		goto done;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
61
62
	}

Howard Chu's avatar
Howard Chu committed
63
	ber_reset( ber, 1 );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
64

65
	rc = get_filter( op, ber, &f, &text );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
66

67
done:
Howard Chu's avatar
Howard Chu committed
68
	ber_free_buf( ber );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
69

70
	return f;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
71
}
72
73
74
75
76

Filter *
str2filter( const char *str )
{
	Operation op = {0};
Howard Chu's avatar
Howard Chu committed
77
	Opheader ohdr = {0};
78

Howard Chu's avatar
Howard Chu committed
79
	op.o_hdr = &ohdr;
80
	op.o_tmpmemctx = NULL;
Howard Chu's avatar
Howard Chu committed
81
	op.o_tmpmfuncs = &ch_mfuncs;
82
83
84

	return str2filter_x( &op, str );
}