The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Utility functions to escape and parse DNs. More...
#include <freeradius-devel/ldap/base.h>
#include <freeradius-devel/util/base16.h>
#include <stdarg.h>
#include <ctype.h>
Go to the source code of this file.
Functions | |
int | fr_ldap_attrs_check (char const **attrs, char const *attr) |
Check that a particular attribute is included in an attribute list. More... | |
uint8_t * | fr_ldap_berval_to_bin (TALLOC_CTX *ctx, struct berval const *in) |
Convert a berval to a talloced buffer. More... | |
char * | fr_ldap_berval_to_string (TALLOC_CTX *ctx, struct berval const *in) |
Convert a berval to a talloced string. More... | |
int | fr_ldap_box_escape (fr_value_box_t *vb, UNUSED void *uctx) |
size_t | fr_ldap_common_dn (char const *full, char const *part) |
Find the place at which the two DN strings diverge. More... | |
int | fr_ldap_filter_to_tmpl (TALLOC_CTX *ctx, tmpl_rules_t const *t_rules, char const **sub, size_t sublen, tmpl_t **out) |
Combine filters and tokenize to a tmpl. More... | |
int | fr_ldap_parse_url_extensions (LDAPControl **sss, size_t sss_len, char *extensions[]) |
Parse a subset (just server side sort for now) of LDAP URL extensions. More... | |
int | fr_ldap_server_config_check (fr_ldap_config_t *handle_config, char const *server, CONF_SECTION *cs) |
Check an LDAP server config in server:port format is valid. More... | |
int | fr_ldap_server_url_check (fr_ldap_config_t *handle_config, char const *server, CONF_SECTION const *cs) |
Check an LDAP server entry in URL format is valid. More... | |
size_t | fr_ldap_uri_escape_func (UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg) |
Converts "bad" strings into ones which are safe for LDAP. More... | |
size_t | fr_ldap_uri_unescape_func (UNUSED request_t *request, char *out, size_t outlen, char const *in, UNUSED void *arg) |
Converts escaped DNs and filter strings into normal. More... | |
char const * | fr_ldap_url_err_to_str (int ldap_url_err) |
Translate the error code emitted from ldap_url_parse and friends into something accessible with fr_strerror() More... | |
bool | fr_ldap_util_is_dn (char const *in, size_t inlen) |
Check whether a string looks like a DN. More... | |
size_t | fr_ldap_util_normalise_dn (char *out, char const *in) |
Normalise escape sequences in a DN. More... | |
Variables | |
static const bool | escapes [UINT8_MAX+1] |
static const char | hextab [] = "0123456789abcdef" |
static USES_APPLE_DEPRECATED_API const char | specials [] = ",+\"\<>;*=()" |
Utility functions to escape and parse DNs.
Definition in file util.c.
int fr_ldap_attrs_check | ( | char const ** | attrs, |
char const * | attr | ||
) |
Check that a particular attribute is included in an attribute list.
[in] | attrs | list to check |
[in] | attr | to look for |
Definition at line 579 of file util.c.
uint8_t* fr_ldap_berval_to_bin | ( | TALLOC_CTX * | ctx, |
struct berval const * | in | ||
) |
char* fr_ldap_berval_to_string | ( | TALLOC_CTX * | ctx, |
struct berval const * | in | ||
) |
Convert a berval to a talloced string.
The ldap_get_values function is deprecated, and ldap_get_values_len does not guarantee the berval buffers it returns are \0 terminated.
For some cases this is fine, for others we require a \0 terminated buffer (feeding DNs back into libldap for example).
ctx | to allocate in. |
in | Berval to copy. |
Definition at line 390 of file util.c.
int fr_ldap_box_escape | ( | fr_value_box_t * | vb, |
UNUSED void * | uctx | ||
) |
size_t fr_ldap_common_dn | ( | char const * | full, |
char const * | part | ||
) |
Find the place at which the two DN strings diverge.
Returns the length of the non matching string in full.
full | DN. |
part | Partial DN as returned by ldap_parse_result. |
Definition at line 488 of file util.c.
int fr_ldap_filter_to_tmpl | ( | TALLOC_CTX * | ctx, |
tmpl_rules_t const * | t_rules, | ||
char const ** | sub, | ||
size_t | sublen, | ||
tmpl_t ** | out | ||
) |
Combine filters and tokenize to a tmpl.
ctx | To allocate combined filter in |
t_rules | Rules for parsing combined filter. |
sub | Array of subfilters (may contain NULLs). |
sublen | Number of potential subfilters in array. |
out | Where to write a pointer to the resulting tmpl. |
Definition at line 517 of file util.c.
int fr_ldap_parse_url_extensions | ( | LDAPControl ** | sss, |
size_t | sss_len, | ||
char * | extensions[] | ||
) |
Parse a subset (just server side sort for now) of LDAP URL extensions.
[out] | sss | Array of LDAPControl * pointers to add controls to. |
[in] | sss_len | How many elements remain in the sss array. |
[in] | extensions | A NULL terminated array of extensions. |
Definition at line 309 of file util.c.
int fr_ldap_server_config_check | ( | fr_ldap_config_t * | handle_config, |
char const * | server, | ||
CONF_SECTION * | cs | ||
) |
Check an LDAP server config in server:port format is valid.
[in,out] | handle_config | LDAP handle config being built |
[in] | server | string to parse |
[in] | cs | in which the server is defined |
Definition at line 701 of file util.c.
int fr_ldap_server_url_check | ( | fr_ldap_config_t * | handle_config, |
char const * | server, | ||
CONF_SECTION const * | cs | ||
) |
Check an LDAP server entry in URL format is valid.
[in,out] | handle_config | LDAP handle config being built |
[in] | server | string to parse |
[in] | cs | in which the server is defined |
Definition at line 605 of file util.c.
size_t fr_ldap_uri_escape_func | ( | UNUSED request_t * | request, |
char * | out, | ||
size_t | outlen, | ||
char const * | in, | ||
UNUSED void * | arg | ||
) |
Converts "bad" strings into ones which are safe for LDAP.
\<hex><hex>format, whereas RFC 4514 indicates that some chars in DNs, may be escaped simply with a backslash. For simplicity, we always use the hex escape sequences. In other areas where we're doing DN comparison, the DNs need to be normalised first so that they both use only hex escape sequences.
Will escape any characters in input strings that would cause the string to be interpreted as part of a DN and or filter. Escape sequence is
\<hex><hex>
.
request | The current request. |
out | Pointer to output buffer. |
outlen | Size of the output buffer. |
in | Raw unescaped string. |
arg | Any additional arguments (unused). |
Definition at line 70 of file util.c.
size_t fr_ldap_uri_unescape_func | ( | UNUSED request_t * | request, |
char * | out, | ||
size_t | outlen, | ||
char const * | in, | ||
UNUSED void * | arg | ||
) |
Converts escaped DNs and filter strings into normal.
\<hex><hex>format, whereas RFC 4514 indicates that some chars in DNs, may be escaped simply with a backslash..
Will unescape any special characters in strings, or
\<hex><hex>
sequences.
request | The current request. |
out | Pointer to output buffer. |
outlen | Size of the output buffer. |
in | Escaped string string. |
arg | Any additional arguments (unused). |
Definition at line 164 of file util.c.
char const* fr_ldap_url_err_to_str | ( | int | ldap_url_err | ) |
Translate the error code emitted from ldap_url_parse and friends into something accessible with fr_strerror()
[in] | ldap_url_err | The error code returned |
Definition at line 742 of file util.c.
Check whether a string looks like a DN.
[in] | in | Str to check. |
[in] | inlen | Length of string to check. |
Definition at line 211 of file util.c.
size_t fr_ldap_util_normalise_dn | ( | char * | out, |
char const * | in | ||
) |
Normalise escape sequences in a DN.
Characters in a DN can either be escaped as
\<hex><hex>
or
\<special>
The LDAP directory chooses how characters are escaped, which can make local comparisons of DNs difficult.
Here we search for hex sequences that match special chars, and convert them to the
\<special>
form.
out | Where to write the normalised DN. |
in | The input DN. |
Definition at line 439 of file util.c.
|
static |