The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
filter.c File Reference

Functions to handle basic LDAP filter parsing and filtering. More...

#include <freeradius-devel/ldap/base.h>
+ Include dependency graph for filter.c:

Go to the source code of this file.

Macros

#define DEBUG_LDAP_ATTR_VAL
 
#define FILTER_ATTR_MAX_LEN   256
 
#define FILTER_VALUE_MAX_LEN   256
 

Functions

bool fr_ldap_filter_eval (fr_dlist_head_t *root, fr_ldap_connection_t *conn, LDAPMessage *msg)
 Evaluate an LDAP filter. More...
 
fr_slen_t fr_ldap_filter_parse (TALLOC_CTX *ctx, fr_dlist_head_t **root, fr_sbuff_t *filter, filter_attr_check_t attr_check, void *uctx)
 Parse an LDAP filter into its component nodes. More...
 
static bool ldap_filter_group_eval (ldap_filter_t *group, fr_ldap_connection_t *conn, LDAPMessage *msg, int depth)
 Evaluate a group of LDAP filters. More...
 
static bool ldap_filter_node_eval (ldap_filter_t *node, fr_ldap_connection_t *conn, LDAPMessage *msg, int depth)
 Evaluate a single LDAP filter node. More...
 
static fr_slen_t ldap_filter_parse_filter (ldap_filter_t *node, fr_sbuff_t *sbuff, int depth, filter_attr_check_t attr_check, void *uctx)
 Parse individual LDAP filter. More...
 
static fr_slen_t ldap_filter_parse_logic (ldap_filter_t *node, fr_sbuff_t *sbuff, int depth, filter_attr_check_t attr_check, void *uctx)
 Parse LDAP filter logic group. More...
 
static fr_slen_t ldap_filter_parse_node (ldap_filter_t *node, fr_sbuff_t *sbuff, int depth, filter_attr_check_t attr_check, void *uctx)
 Parse individual LDAP filter nodes. More...
 

Variables

static bool const fr_ldap_attr_allowed_chars [UINT8_MAX+1]
 
static fr_table_num_sorted_t const ldap_filter_op_table []
 
static size_t ldap_filter_op_table_len = NUM_ELEMENTS(ldap_filter_op_table)
 

Detailed Description

Functions to handle basic LDAP filter parsing and filtering.

Id
f62246f98c32488ea3287c3b5732984cd1033607

Definition in file filter.c.

Macro Definition Documentation

◆ DEBUG_LDAP_ATTR_VAL

#define DEBUG_LDAP_ATTR_VAL
Value:
if (DEBUG_ENABLED3) { \
fr_value_box_t value_box; \
fr_ldap_berval_to_value_str_shallow(&value_box, values[i]); \
DEBUG3("%*s Evaluating attribute \"%s\", value \"%pV\"", depth, "", node->attr, &value_box); \
}
#define DEBUG_ENABLED3
True if global debug level 1-3 messages are enabled.
Definition: log.h:259
static uint8_t depth(fr_minmax_heap_index_t i)
Definition: minmax_heap.c:83

Definition at line 411 of file filter.c.

◆ FILTER_ATTR_MAX_LEN

#define FILTER_ATTR_MAX_LEN   256

Definition at line 39 of file filter.c.

◆ FILTER_VALUE_MAX_LEN

#define FILTER_VALUE_MAX_LEN   256

Definition at line 40 of file filter.c.

Function Documentation

◆ fr_ldap_filter_eval()

bool fr_ldap_filter_eval ( fr_dlist_head_t root,
fr_ldap_connection_t conn,
LDAPMessage *  msg 
)

Evaluate an LDAP filter.

Parameters
[in]rootof the LDAP filter to evaluate.
[in]connLDAP connection the message being filtered was returned on.
[in]msgto filter.
Returns
true or false result of the node evaluation.

Definition at line 583 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_ldap_filter_parse()

fr_slen_t fr_ldap_filter_parse ( TALLOC_CTX *  ctx,
fr_dlist_head_t **  root,
fr_sbuff_t filter,
filter_attr_check_t  attr_check,
void *  uctx 
)

Parse an LDAP filter into its component nodes.

Parameters
[in]ctxto allocate nodes in.
[in,out]rootwhere to allocate the root of the parsed filter.
[in]filterto parse.
[in]attr_checkcallback to check if required attributes are in the query.
[in]uctxpassed to attribute check callback.
Returns
  • number of bytes parsed on success < 0 on failure

Definition at line 343 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ldap_filter_group_eval()

static bool ldap_filter_group_eval ( ldap_filter_t group,
fr_ldap_connection_t conn,
LDAPMessage *  msg,
int  depth 
)
static

Evaluate a group of LDAP filters.

Groups have a logical operator of &, | or !

Parameters
[in]groupto evaluate.
[in]connLDAP connection the message being filtered was returned on
[in]msgto filter
[in]depthto indent debug messages, reflecting group nesting
Returns
true or false result of the group evaluation

Definition at line 377 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ldap_filter_node_eval()

static bool ldap_filter_node_eval ( ldap_filter_t node,
fr_ldap_connection_t conn,
LDAPMessage *  msg,
int  depth 
)
static

Evaluate a single LDAP filter node.

Parameters
[in]nodeto evaluate.
[in]connLDAP connection the message being filtered was returned on.
[in]msgto filter.
[in]depthto indent debug messages, reflecting group nesting.
Returns
true or false result of the node evaluation.

Definition at line 425 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ldap_filter_parse_filter()

static fr_slen_t ldap_filter_parse_filter ( ldap_filter_t node,
fr_sbuff_t sbuff,
int  depth,
filter_attr_check_t  attr_check,
void *  uctx 
)
static

Parse individual LDAP filter.

Parameters
[in,out]nodeto populate with parsed filter.
[in]sbuffpointing to filter to parse.
[in]depthto indent debug output, indicating nesting of groups.
[in]attr_checkcallback to check if required attributes are in the query.
[in]uctxpassed to attribute check callback.
Returns
  • number of bytes parsed on success
  • < 0 on error

Definition at line 121 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ldap_filter_parse_logic()

static fr_slen_t ldap_filter_parse_logic ( ldap_filter_t node,
fr_sbuff_t sbuff,
int  depth,
filter_attr_check_t  attr_check,
void *  uctx 
)
static

Parse LDAP filter logic group.

Parameters
[in,out]nodeto populate with parsed filter.
[in]sbuffpointing to filter to parse.
[in]depthto indent debug output, indicating nesting of groups.
[in]attr_checkcallback to check if required attributes are in the query.
[in]uctxpassed to attribute check callback.
Returns
  • number of bytes parsed on success
  • < 0 on error

Definition at line 56 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ldap_filter_parse_node()

static fr_slen_t ldap_filter_parse_node ( ldap_filter_t node,
fr_sbuff_t sbuff,
int  depth,
filter_attr_check_t  attr_check,
void *  uctx 
)
static

Parse individual LDAP filter nodes.

A node can either be a group of nodes joined with a logical operator or an individual filter.

Parameters
[in,out]nodeto populate with parsed filter.
[in]sbuffpointing to filter to parse.
[in]depthto indent debug output, indicating nesting of groups.
[in]attr_checkcallback to check if required attributes are in the query.
[in]uctxpassed to attribute check callback.
Returns
  • number of bytes parsed on success
  • < 0 on error

Definition at line 283 of file filter.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ fr_ldap_attr_allowed_chars

bool const fr_ldap_attr_allowed_chars[UINT8_MAX+1]
static
Initial value:
= {
['-'] = true,
}
#define SBUFF_CHAR_CLASS_ALPHA_NUM

Definition at line 34 of file filter.c.

◆ ldap_filter_op_table

fr_table_num_sorted_t const ldap_filter_op_table[]
static
Initial value:
= {
{ L("<="), LDAP_FILTER_OP_LE },
{ L("="), LDAP_FILTER_OP_EQ },
{ L(">="), LDAP_FILTER_OP_GE }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ LDAP_FILTER_OP_EQ
Attribute equals value.
Definition: base.h:546
@ LDAP_FILTER_OP_LE
Attribute less than or equal to value.
Definition: base.h:550
@ LDAP_FILTER_OP_GE
Attribute greater than or equal to value.
Definition: base.h:549

Definition at line 27 of file filter.c.

◆ ldap_filter_op_table_len

size_t ldap_filter_op_table_len = NUM_ELEMENTS(ldap_filter_op_table)
static

Definition at line 32 of file filter.c.