c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef USERDB_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define USERDB_H
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen#include "md5.h"
ee6df9526e9716b3f1734d85b566e00fc41208bcTimo Sirainen#include "auth-fields.h"
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen
e76073ebaf90fa29abfdc364873acf78983949aaTimo Sirainenstruct auth;
1e21e6be70994b1aa9e52ca0e2f51afefca6d0dfTimo Sirainenstruct auth_request;
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainenstruct auth_userdb_settings;
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainenenum userdb_result {
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen USERDB_RESULT_INTERNAL_FAILURE = -1,
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen USERDB_RESULT_USER_UNKNOWN = -2,
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen USERDB_RESULT_OK = 1
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen};
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainentypedef void userdb_callback_t(enum userdb_result result,
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainen struct auth_request *request);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen/* user=NULL when there are no more users */
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainentypedef void userdb_iter_callback_t(const char *user, void *context);
22535a9e685e29214082878e37a267157044618eTimo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainenstruct userdb_module {
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen const char *args;
74674a53a72dab535c61f455b2246ef2797844eaTimo Sirainen /* The default caching key for this module, or NULL if caching isn't
74674a53a72dab535c61f455b2246ef2797844eaTimo Sirainen wanted. This is updated by settings in auth_userdb. */
74674a53a72dab535c61f455b2246ef2797844eaTimo Sirainen const char *default_cache_key;
c5383a0ed56a188a7d5efaaa4c6f8243af432d65Timo Sirainen
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainen /* If blocking is set to TRUE, use child processes to access
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen this userdb. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen bool blocking;
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen /* id is used by blocking userdb to identify the userdb */
3cf67672fdc87583cb23ce088c95bb5dee60e74dTimo Sirainen unsigned int id;
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen /* number of time init() has been called */
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen int init_refcount;
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen
2d8f66596f445dd8b399b7032c3f0e9202015b63Timo Sirainen /* WARNING: avoid adding anything here that isn't based on args.
2d8f66596f445dd8b399b7032c3f0e9202015b63Timo Sirainen if you do, you need to change userdb.c:userdb_find() also to avoid
2d8f66596f445dd8b399b7032c3f0e9202015b63Timo Sirainen accidentally merging wrong userdbs. */
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen const struct userdb_module_interface *iface;
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen};
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainenstruct userdb_iterate_context {
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen struct auth_request *auth_request;
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen userdb_iter_callback_t *callback;
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen void *context;
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen bool failed;
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen};
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainenstruct userdb_module_interface {
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen const char *name;
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainen struct userdb_module *(*preinit)(pool_t pool, const char *args);
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainen void (*init)(struct userdb_module *module);
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainen void (*deinit)(struct userdb_module *module);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainen void (*lookup)(struct auth_request *auth_request,
66d2db642fe24d555d113ba463e446b038d476efTimo Sirainen userdb_callback_t *callback);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen struct userdb_iterate_context *
e9371f899a3d4207a0ffd3923ea5ec7250cf5e75Timo Sirainen (*iterate_init)(struct auth_request *auth_request,
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen userdb_iter_callback_t *callback,
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen void *context);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen void (*iterate_next)(struct userdb_iterate_context *ctx);
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen int (*iterate_deinit)(struct userdb_iterate_context *ctx);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen};
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenuid_t userdb_parse_uid(struct auth_request *request, const char *str)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen ATTR_NULL(1);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainengid_t userdb_parse_gid(struct auth_request *request, const char *str)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen ATTR_NULL(1);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainenstruct userdb_module *
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainenuserdb_preinit(pool_t pool, const struct auth_userdb_settings *set);
f3d506e525a720f214020ca0f989a1966b30edaeTimo Sirainenvoid userdb_init(struct userdb_module *userdb);
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainenvoid userdb_deinit(struct userdb_module *userdb);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdb_register_module(struct userdb_module_interface *iface);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdb_unregister_module(struct userdb_module_interface *iface);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvivoid userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN]);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdbs_init(void);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdbs_deinit(void);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen
1e21e6be70994b1aa9e52ca0e2f51afefca6d0dfTimo Sirainen#include "auth-request.h"
1e21e6be70994b1aa9e52ca0e2f51afefca6d0dfTimo Sirainen
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#endif