ldap-client.h revision d3be0145dff35c54c3c89c3ad3e1afd2c486a2d4
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye#ifndef LDAP_CLIENT_H
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye#define LDAP_CLIENT_H
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyeenum ldap_scope {
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye LDAP_SEARCH_SCOPE_BASE = 0x0000,
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye LDAP_SEARCH_SCOPE_ONE = 0x0001,
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye LDAP_SEARCH_SCOPE_SUBTREE = 0x0002
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye};
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyestruct ldap_client;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyestruct ldap_result;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyestruct ldap_search_iterator;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyestruct ldap_entry;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye/* Called when the LDAP result has finished. The callback must verify first
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye if the result is valid or not by calling ldap_result_has_failed() or
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye ldap_result_get_error(). The result is freed automatically after this
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye callback finishes. */
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyetypedef void ldap_result_callback_t(struct ldap_result *result, void *context);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozinastruct ldap_client_settings {
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina const char *uri;
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina const char *bind_dn;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const char *password;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const struct ssl_iostream_settings *ssl_set;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
77bb616a49abcd468b37a4416385df92d1f698c6Trond Norbye unsigned int timeout_secs;
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlen unsigned int max_idle_time_secs;
77bb616a49abcd468b37a4416385df92d1f698c6Trond Norbye unsigned int debug;
57065c0b4d57ca1e0182adda16962b22987a5b95Knut Anders Hatlen bool require_ssl;
57065c0b4d57ca1e0182adda16962b22987a5b95Knut Anders Hatlen bool start_tls;
854585887bca366ee433303cae0e99572240a568Trond Norbye};
854585887bca366ee433303cae0e99572240a568Trond Norbye
6336b638e9afd018de5f6c516eac4775d140fdaeJHKSTstruct ldap_search_input {
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlen const char *base_dn;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const char *filter;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const char *const *attributes;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye enum ldap_scope scope;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye unsigned int size_limit;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
6336b638e9afd018de5f6c516eac4775d140fdaeJHKST unsigned int timeout_secs;
6336b638e9afd018de5f6c516eac4775d140fdaeJHKST};
6336b638e9afd018de5f6c516eac4775d140fdaeJHKST
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyestruct ldap_compare_input {
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlen const char *dn;
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const char *attr;
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina const char *value;
9e81ea65408ad01e22a2c01118fd29139e20336bJorgen Austvik
9e81ea65408ad01e22a2c01118fd29139e20336bJorgen Austvik unsigned int timeout_secs;
04eceded116c11ab5ed16e40196adbe969b94aabJorgen Austvik};
9e81ea65408ad01e22a2c01118fd29139e20336bJorgen Austvik
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlen/* Initialize LDAP. Returns 0 on success, or -1 and error_r if initialization
57065c0b4d57ca1e0182adda16962b22987a5b95Knut Anders Hatlen failed with the given settings. */
d5f75284ca588815c2f7de683d7ade1277418219Peter Brayint ldap_client_init(const struct ldap_client_settings *set,
ff5eba819da0cf7964d884630fb13262ef12c505Trond Norbye struct ldap_client **client_r, const char **error_r);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyevoid ldap_client_deinit(struct ldap_client **client);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyevoid ldap_client_switch_ioloop(struct ldap_client *client);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
57065c0b4d57ca1e0182adda16962b22987a5b95Knut Anders Hatlenvoid ldap_search_start(struct ldap_client *client,
d5f75284ca588815c2f7de683d7ade1277418219Peter Bray const struct ldap_search_input *input,
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye ldap_result_callback_t *callback,
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina void *context);
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina#define ldap_search_start(client, input, callback, context) \
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina ldap_search_start(client, input + \
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina CALLBACK_TYPECHECK(callback, void (*)( \
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina struct ldap_result *, typeof(context))), \
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina (ldap_result_callback_t *)callback, context)
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina/* Returns TRUE if the LDAP query failed and result must not be used further. */
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozinabool ldap_result_has_failed(struct ldap_result *result);
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina/* Returns the error string if the query had failed, or NULL if it hasn't. */
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozinaconst char *ldap_result_get_error(struct ldap_result *result);
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina
ff5eba819da0cf7964d884630fb13262ef12c505Trond Norbyestruct ldap_search_iterator* ldap_search_iterator_init(struct ldap_result *result);
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlenconst struct ldap_entry *ldap_search_iterator_next(struct ldap_search_iterator *iter);
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozinavoid ldap_search_iterator_deinit(struct ldap_search_iterator **iter);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
04455c685e53d0a29925b147a936d0a6a30cb1dcJorgen Austvikvoid ldap_compare_start(struct ldap_client *client,
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye const struct ldap_compare_input *input,
3ba66fbb56ef22f183da783a1b2718280c357a4eStanislav Kozina ldap_result_callback_t *callback, void *context);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye#define ldap_compare_start(client, input, callback, context) \
ebb9f739bca3bc9382340b628554b484e4837d6aKnut Anders Hatlen ldap_compare_start(client, input + \
57065c0b4d57ca1e0182adda16962b22987a5b95Knut Anders Hatlen CALLBACK_TYPECHECK(callback, void (*)( \
d5f75284ca588815c2f7de683d7ade1277418219Peter Bray struct ldap_result *, typeof(context))), \
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye (ldap_result_callback_t *)callback, context)
ff5eba819da0cf7964d884630fb13262ef12c505Trond Norbye/* Returns TRUE if the comparison matched, FALSE if not. */
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyebool ldap_compare_result(struct ldap_result *result);
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbye
090c0a68a18125bd61e290b74f3dcd8817dab986Trond Norbyeconst char *ldap_entry_dn(const struct ldap_entry *entry);
d5f75284ca588815c2f7de683d7ade1277418219Peter Brayconst char *const *ldap_entry_get_attributes(const struct ldap_entry *entry);
d5f75284ca588815c2f7de683d7ade1277418219Peter Brayconst char *const *ldap_entry_get_attribute(const struct ldap_entry *entry, const char *attribute);
854585887bca366ee433303cae0e99572240a568Trond Norbye
6336b638e9afd018de5f6c516eac4775d140fdaeJHKST#endif
6336b638e9afd018de5f6c516eac4775d140fdaeJHKST