Sovite.LDAP.Filter (sovite v0.2.0)

Copy Markdown View Source

Parses RFC 4515 LDAP search filters into :eldap filters, with placeholders filled in after parsing.

A placeholder is % and a letter; build/2 takes the value of each letter, such as %{"u" => "alice@example.com"}. %% is a %, and a letter without a value is left as it is.

Because placeholders are replaced in the parsed values, input cannot change the filter's structure: *)(uid=* is just a strange name, never an injection.

iex> {:ok, filter} = Sovite.LDAP.Filter.parse("(&(objectClass=person)(mail=%u))")
iex> Sovite.LDAP.Filter.build(filter, %{"u" => "a*b@example.com"})
{:and, [{:equalityMatch, {:AttributeValueAssertion, ~c"objectClass", ~c"person"}}, {:equalityMatch, {:AttributeValueAssertion, ~c"mail", ~c"a*b@example.com"}}]}

Summary

Types

t()

A parsed filter, to fill in with build/2.

Functions

Fills in the placeholders from values and returns an :eldap filter.

Parses a filter string. Returns :error for invalid syntax.

Replaces the placeholders in string with values, escaping each value with escape.

Types

t()

@type t() :: tuple()

A parsed filter, to fill in with build/2.

Functions

build(arg, values)

@spec build(t(), %{required(String.t()) => binary()}) :: term()

Fills in the placeholders from values and returns an :eldap filter.

parse(string)

@spec parse(String.t()) :: {:ok, t()} | :error

Parses a filter string. Returns :error for invalid syntax.

substitute(string, values, escape \\ & &1)

@spec substitute(String.t(), %{required(String.t()) => binary()}, (binary() ->
                                                               binary())) ::
  binary()

Replaces the placeholders in string with values, escaping each value with escape.