userdb.h revision e9371f899a3d4207a0ffd3923ea5ec7250cf5e75
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen#ifndef USERDB_H
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#define USERDB_H
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#include "md5.h"
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#include "auth-stream.h"
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
a1607f6001a9949e1cf9d49eb0aa936dbb4c77ffTimo Sirainenstruct auth;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct auth_request;
00d58fcfe8191d6ce7efa801d289a5c0fe88d1aeTimo Sirainenstruct auth_userdb_settings;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenenum userdb_result {
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen USERDB_RESULT_INTERNAL_FAILURE = -1,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen USERDB_RESULT_USER_UNKNOWN = -2,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen USERDB_RESULT_OK = 1
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainentypedef void userdb_callback_t(enum userdb_result result,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct auth_request *request);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen/* user=NULL when there are no more users */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainentypedef void userdb_iter_callback_t(const char *user, void *context);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstruct userdb_module {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen const char *args;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* The caching key for this module, or NULL if caching isn't wanted. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *cache_key;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen /* If blocking is set to TRUE, use child processes to access
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen this userdb. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen bool blocking;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* id is used by blocking userdb to identify the userdb */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen unsigned int id;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* number of time init() has been called */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen int init_refcount;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct userdb_template *default_fields_tmpl;
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen struct userdb_template *override_fields_tmpl;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const struct userdb_module_interface *iface;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen};
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainen
f6c1297c26b355c4aec2a08978f51ec3efecb351Timo Sirainenstruct userdb_iterate_context {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen struct auth_request *auth_request;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen userdb_iter_callback_t *callback;
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen void *context;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen bool failed;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct userdb_module_interface {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *name;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct userdb_module *(*preinit)(pool_t pool, const char *args);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen void (*init)(struct userdb_module *module);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen void (*deinit)(struct userdb_module *module);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen void (*lookup)(struct auth_request *auth_request,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen userdb_callback_t *callback);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct userdb_iterate_context *
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen (*iterate_init)(struct auth_request *auth_request,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen userdb_iter_callback_t *callback,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen void *context);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen void (*iterate_next)(struct userdb_iterate_context *ctx);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen int (*iterate_deinit)(struct userdb_iterate_context *ctx);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen};
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenuid_t userdb_parse_uid(struct auth_request *request, const char *str);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainengid_t userdb_parse_gid(struct auth_request *request, const char *str);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstruct userdb_module *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenuserdb_preinit(pool_t pool, const struct auth_userdb_settings *set);
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainenvoid userdb_init(struct userdb_module *userdb);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenvoid userdb_deinit(struct userdb_module *userdb);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenvoid userdb_register_module(struct userdb_module_interface *iface);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenvoid userdb_unregister_module(struct userdb_module_interface *iface);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenvoid userdbs_generate_md5(unsigned char md5[MD5_RESULTLEN]);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainenvoid userdbs_init(void);
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainenvoid userdbs_deinit(void);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#include "auth-request.h"
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#endif
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen