db-ldap.h revision c4457e497e01b57565d24da624968699b166e02a
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen#ifndef __DB_LDAP_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define __DB_LDAP_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen#include <ldap.h>
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
ef4d0eafab4d26bba047551db1e23ceff8aa9404Timo Sirainenstruct ldap_connection;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct ldap_request;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentypedef void db_search_callback_t(struct ldap_connection *conn,
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen struct ldap_request *request,
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen LDAPMessage *res);
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainenstruct ldap_settings {
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *hosts;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *dn;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *dnpass;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *deref;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *scope;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *base;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *user_attrs;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *user_filter;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *pass_attrs;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen const char *pass_filter;
afd0d073a0afd1c8cf6473b4ae76919586eaa1faTimo Sirainen
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen unsigned int user_global_uid;
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen unsigned int user_global_gid;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
75e8db37023fde9ac15550bf426be8719d94a821Timo Sirainen int ldap_deref, ldap_scope;
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen};
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainenstruct ldap_connection {
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen struct ldap_connection *next;
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen pool_t pool;
7d7b5c98f086ffa8ac9c90f21db17748ca607202Timo Sirainen int refcount;
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen char *config_path;
e627cdc5ef30d87959f9510832427e33a2f1d84aTimo Sirainen struct ldap_settings set;
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen LDAP *ld;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen struct io *io;
24fc71a693331ffe77e2b6d81c70aca6fa055e47Timo Sirainen struct hash_table *requests;
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen unsigned int connected:1;
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen};
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainen
ff7257145f317d6ca44a9402427bb74c34b999a9Timo Sirainenstruct ldap_request {
ff7257145f317d6ca44a9402427bb74c34b999a9Timo Sirainen db_search_callback_t *callback;
ff7257145f317d6ca44a9402427bb74c34b999a9Timo Sirainen void *context;
1727610dbc69920b7f0d0622b4e5d7127c59093dTimo Sirainen};
ef4d0eafab4d26bba047551db1e23ceff8aa9404Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid db_ldap_search(struct ldap_connection *conn, const char *base, int scope,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *filter, char **attributes,
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen struct ldap_request *request);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainenvoid db_ldap_set_attrs(struct ldap_connection *conn, const char *value,
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen unsigned int **attrs, char ***attr_names);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainenstruct ldap_connection *db_ldap_init(const char *config_path);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid db_ldap_unref(struct ldap_connection *conn);
1b3bb8d39686ed24730cbc31cc9a33dc62c8c6c3Timo Sirainen
ef4d0eafab4d26bba047551db1e23ceff8aa9404Timo Sirainen#endif
1727610dbc69920b7f0d0622b4e5d7127c59093dTimo Sirainen