db-ldap.h revision d5cebe7f98e63d4e2822863ef2faa4971e8b3a5d
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen#ifndef __DB_LDAP_H
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen#define __DB_LDAP_H
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen#include <ldap.h>
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainenstruct ldap_connection;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainenstruct ldap_request;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainentypedef void db_search_callback_t(struct ldap_connection *conn,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen struct ldap_request *request,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen LDAPMessage *res);
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainenstruct ldap_settings {
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen const char *hosts;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen const char *uris;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen const char *dn;
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen const char *dnpass;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen bool auth_bind;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen const char *auth_bind_userdn;
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen const char *deref;
42dbeeb3462895b03e7633dbc59e8e191199734bTimo Sirainen const char *scope;
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen const char *base;
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen unsigned int ldap_version;
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen const char *user_attrs;
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen const char *user_filter;
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen const char *pass_attrs;
e815af0640b38444b31eadfaa1673bcb422e1573Timo Sirainen const char *pass_filter;
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen
1a266561b099269bef75eee1a3742e61130ef780Timo Sirainen const char *default_pass_scheme;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen const char *user_global_uid;
5fe5ea74285e2fc0fbf7568c53f251aa894650fbTimo Sirainen const char *user_global_gid;
dd2df6a67f10792ce31a3666197c0b6885893a3aTimo Sirainen
14175321ddb88619015866978c05a27786ca4814Timo Sirainen /* ... */
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen int ldap_deref, ldap_scope;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen uid_t uid;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen gid_t gid;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen};
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainenstruct ldap_connection {
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen struct ldap_connection *next;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen pool_t pool;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen int refcount;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen char *config_path;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen struct ldap_settings set;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen LDAP *ld;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen struct io *io;
1de2b5a16a455e018d8cbf72ee114d4b5d557a48Timo Sirainen struct hash_table *requests;
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen char **pass_attr_names, **user_attr_names;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen struct hash_table *pass_attr_map, *user_attr_map;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen unsigned int connected:1;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen};
a33b41b1dc19c692b1283049ec4de492fdadeb9aTimo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenstruct ldap_request {
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen db_search_callback_t *callback;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen void *context;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen const char *base;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen const char *filter;
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen char **attributes; /* points to pass_attr_names / user_attr_names */
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen};
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenvoid db_ldap_search(struct ldap_connection *conn, struct ldap_request *request,
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen int scope);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenvoid db_ldap_set_attrs(struct ldap_connection *conn, const char *attrlist,
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen char ***attr_names_r, struct hash_table *attr_map,
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen const char *const default_attr_map[]);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenstruct ldap_connection *db_ldap_init(const char *config_path);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenvoid db_ldap_unref(struct ldap_connection **conn);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenbool db_ldap_connect(struct ldap_connection *conn);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenconst char *ldap_escape(const char *str);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainenconst char *ldap_get_error(struct ldap_connection *conn);
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen#endif
8ad2759cf4073e3bf4fcb9222a86e2153ed31875Timo Sirainen