pub struct RustLDAP { /* private fields */ }Expand description
A high level abstraction over the raw OpenLDAP functions.
A RustLDAP object hides raw OpenLDAP complexities and exposes a simple object that is
created, configured, and queried. Methods that call underlying OpenLDAP calls that can fail
will raise an errors::LDAPError with additional details.
Using a RustLDAP object is easy!
Implementations§
Source§impl RustLDAP
impl RustLDAP
Sourcepub fn new(uri: &str) -> Result<RustLDAP, LDAPError>
pub fn new(uri: &str) -> Result<RustLDAP, LDAPError>
Create a new RustLDAP.
Creates a new RustLDAP and initializes underlying OpenLDAP library. Upon creation, a
subsequent calls to set_option and simple_bind are possible. Before calling a search
related function, one must bind to the server by calling simple_bind. See module usage
information for more details on using a RustLDAP object.
§Parameters
- uri - URI of the LDAP server to connect to. E.g., ldaps://localhost:636.
Sourcepub fn set_option<T: LDAPOptionValue + ?Sized>(
&self,
option: i32,
value: &T,
) -> bool
pub fn set_option<T: LDAPOptionValue + ?Sized>( &self, option: i32, value: &T, ) -> bool
Sets an option on the LDAP connection.
When setting an option to ON or OFF one may use the boolean values true or false,
respectively.
§Parameters
- option - An option identifier from
cldap::codes. - value - The value to set for the option.
Sourcepub fn simple_bind(&self, who: &str, pass: &str) -> Result<i32, LDAPError>
pub fn simple_bind(&self, who: &str, pass: &str) -> Result<i32, LDAPError>
Bind to the LDAP server.
If you wish to configure options on the LDAP server, be sure to set required options using
set_option before binding to the LDAP server. In some advanced cases, it may be required
to set multiple options for an option to be made available. Refer to the OpenLDAP
documentation for information on available options and how to use them.
§Parameters
- who - The user’s name to bind with.
- pass - The user’s password to bind with.
Sourcepub fn simple_search(
&self,
base: &str,
scope: i32,
) -> Result<LDAPResponse, LDAPError>
pub fn simple_search( &self, base: &str, scope: i32, ) -> Result<LDAPResponse, LDAPError>
Simple synchronous search.
Performs a simple search with only the base, returning all attributes found.
§Parameters
- base - The LDAP base.
- scope - The search scope. See
cldap::codes::scopes.
Sourcepub fn start_tls(
&self,
serverctrls: Option<*mut *mut LDAPControl>,
clientctrls: Option<*mut *mut LDAPControl>,
) -> Result<i32, LDAPError>
pub fn start_tls( &self, serverctrls: Option<*mut *mut LDAPControl>, clientctrls: Option<*mut *mut LDAPControl>, ) -> Result<i32, LDAPError>
Installs TLS handlers on the session
§Examples
use openldap::RustLDAP;
let ldap = RustLDAP::new(&"ldaps://myserver:636").unwrap();
ldap.set_option(
openldap::codes::options::LDAP_OPT_PROTOCOL_VERSION,
&openldap::codes::versions::LDAP_VERSION3,
);
ldap.set_option(
openldap::codes::options::LDAP_OPT_X_TLS_REQUIRE_CERT,
&openldap::codes::options::LDAP_OPT_X_TLS_ALLOW,
);
ldap.set_option(openldap::codes::options::LDAP_OPT_X_TLS_NEWCTX, &0);
ldap.start_tls(None, None);
ldap.simple_bind("some-dn", "some-password").unwrap();Sourcepub fn ldap_search(
&self,
base: &str,
scope: i32,
filter: Option<&str>,
attrs: Option<Vec<&str>>,
attrsonly: bool,
serverctrls: Option<*mut *mut LDAPControl>,
clientctrls: Option<*mut *mut LDAPControl>,
timeout: *mut timeval,
sizelimit: i32,
) -> Result<LDAPResponse, LDAPError>
pub fn ldap_search( &self, base: &str, scope: i32, filter: Option<&str>, attrs: Option<Vec<&str>>, attrsonly: bool, serverctrls: Option<*mut *mut LDAPControl>, clientctrls: Option<*mut *mut LDAPControl>, timeout: *mut timeval, sizelimit: i32, ) -> Result<LDAPResponse, LDAPError>
Advanced synchronous search.
Exposes a raw API around the underlying ldap_search_ext_s function from OpenLDAP.
Wherever possible, use provided wrappers.
§Parameters
- base - The base domain.
- scope - The search scope. See
cldap::codes::scopes. - filter - An optional filter.
- attrs - An optional set of attrs.
- attrsonly - True if should return only the attrs specified in
attrs. - serverctrls - Optional sever controls.
- clientctrls - Optional client controls.
- timeout - A timeout.
- sizelimit - The maximum number of entities to return, or -1 for no limit.