2003-11-26 20:17:14 -05:00
|
|
|
/* str2filter.c - parse an RFC 2554 string filter */
|
1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 20:17:14 -05:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
|
*
|
2004-01-01 14:15:16 -05:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-26 20:17:14 -05:00
|
|
|
* 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.
|
1999-08-06 19:07:46 -04:00
|
|
|
*/
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-10-24 21:41:42 -04:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-15 17:40:11 -05:00
|
|
|
#include <ac/ctype.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include "slap.h"
|
1999-08-30 20:44:49 -04:00
|
|
|
#include <ldap_pvt.h>
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-11-25 18:37:10 -05:00
|
|
|
#if 0 /* unused */
|
2000-02-14 15:57:34 -05:00
|
|
|
static char *find_matching_paren( const char *s );
|
2002-11-25 18:37:10 -05:00
|
|
|
#endif /* unused */
|
2000-02-14 15:57:34 -05:00
|
|
|
static Filter *str2list( const char *str, long unsigned int ftype);
|
|
|
|
|
static Filter *str2simple( const char *str);
|
|
|
|
|
static int str2subvals( const char *val, Filter *f);
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
Filter *
|
2003-04-09 12:52:03 -04:00
|
|
|
str2filter_x( Operation *op, const char *str )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
2002-03-11 00:21:49 -05:00
|
|
|
int rc;
|
1998-10-23 17:51:32 -04:00
|
|
|
Filter *f = NULL;
|
2003-10-12 00:45:09 -04:00
|
|
|
BerElementBuffer berbuf;
|
|
|
|
|
BerElement *ber = (BerElement *)&berbuf;
|
2002-03-11 00:21:49 -05:00
|
|
|
const char *text = NULL;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2001-01-15 14:17:29 -05:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-11 16:33:24 -04:00
|
|
|
LDAP_LOG( FILTER, ENTRY, "str2filter: \"%s\"\n", str, 0, 0 );
|
2001-01-15 14:17:29 -05:00
|
|
|
#else
|
1998-08-08 20:43:13 -04:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "str2filter \"%s\"\n", str, 0, 0 );
|
2001-01-15 14:17:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
if ( str == NULL || *str == '\0' ) {
|
2002-01-02 14:06:49 -05:00
|
|
|
return NULL;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2002-12-18 14:00:23 -05:00
|
|
|
ber_init2( ber, NULL, LBER_USE_DER );
|
2003-04-09 12:52:03 -04:00
|
|
|
if ( op->o_tmpmemctx ) {
|
2003-05-28 18:17:08 -04:00
|
|
|
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
|
2003-04-09 12:52:03 -04:00
|
|
|
}
|
2002-01-02 14:06:49 -05:00
|
|
|
|
2002-03-29 19:42:40 -05:00
|
|
|
rc = ldap_pvt_put_filter( ber, str );
|
2002-03-11 00:21:49 -05:00
|
|
|
if( rc < 0 ) {
|
|
|
|
|
goto done;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2002-12-18 14:00:23 -05:00
|
|
|
ber_reset( ber, 1 );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
rc = get_filter( op, ber, &f, &text );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
done:
|
2002-12-18 14:00:23 -05:00
|
|
|
ber_free_buf( ber );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
return f;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-04-09 12:52:03 -04:00
|
|
|
|
|
|
|
|
Filter *
|
|
|
|
|
str2filter( const char *str )
|
|
|
|
|
{
|
|
|
|
|
Operation op = {0};
|
|
|
|
|
|
|
|
|
|
op.o_tmpmemctx = NULL;
|
2003-04-09 19:37:00 -04:00
|
|
|
op.o_tmpmfuncs = &ch_mfuncs;
|
2003-04-09 12:52:03 -04:00
|
|
|
|
|
|
|
|
return str2filter_x( &op, str );
|
|
|
|
|
}
|