1998-08-08 20:43:13 -04:00
|
|
|
/* str2filter.c - parse an rfc 1588 string filter */
|
1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-06 19:07:46 -04:00
|
|
|
/*
|
2002-01-04 16:17:25 -05:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-06 19:07:46 -04:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
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
|
|
|
|
2000-02-14 15:57:34 -05:00
|
|
|
static char *find_matching_paren( const char *s );
|
|
|
|
|
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 *
|
2000-02-14 15:57:34 -05:00
|
|
|
str2filter( 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;
|
2002-03-11 00:21:49 -05:00
|
|
|
BerElement *ber;
|
|
|
|
|
char berbuf[256];
|
|
|
|
|
struct berval *bv = NULL;
|
|
|
|
|
Connection conn;
|
|
|
|
|
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-03-11 00:21:49 -05:00
|
|
|
ber = ber_alloc_t( LBER_USE_DER );
|
|
|
|
|
if( ber == NULL ) {
|
2002-01-02 13:48:10 -05:00
|
|
|
return NULL;
|
1998-08-08 20:43:13 -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-03-11 00:21:49 -05:00
|
|
|
rc = ber_flatten( ber, &bv );
|
|
|
|
|
if( rc < 0 ) {
|
|
|
|
|
goto done;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
ber_free( ber, 0 );
|
2000-05-14 20:41:29 -04:00
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
ber = (BerElement *)berbuf;
|
|
|
|
|
ber_init2( ber, bv, 0 );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
conn.c_connid = 0;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
rc = get_filter( &conn, ber, &f, &text );
|
|
|
|
|
if( rc ) {
|
|
|
|
|
goto done;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2002-03-11 00:21:49 -05:00
|
|
|
done:
|
|
|
|
|
ber_bvfree( bv );
|
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
|
|
|
}
|