userdb.c revision 9261dbf0675204898c6557591c7aa376e23a52b2
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainenstatic ARRAY_DEFINE(userdb_interfaces, struct userdb_module_interface *);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic ARRAY_DEFINE(userdb_modules, struct userdb_module *);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct userdb_module_interface *userdb_interface_find(const char *name)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct userdb_module_interface *const *ifaces;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen struct userdb_module_interface *iface = *ifaces;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid userdb_register_module(struct userdb_module_interface *iface)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen old_iface = userdb_interface_find(iface->name);
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen if (old_iface != NULL && old_iface->lookup == NULL) {
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen /* replacing a "support not compiled in" userdb */
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainen i_panic("userdb_register_module(%s): Already registered",
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenvoid userdb_unregister_module(struct userdb_module_interface *iface)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen struct userdb_module_interface *const *ifaces;
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen unsigned int idx;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen idx = array_foreach_idx(&userdb_interfaces, ifaces);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_panic("userdb_unregister_module(%s): Not registered", iface->name);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenuid_t userdb_parse_uid(struct auth_request *request, const char *str)
20a802016205bbcafc90f164f769ea801f88d014Timo Sirainengid_t userdb_parse_gid(struct auth_request *request, const char *str)
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainenuserdb_find(const char *driver, const char *args, unsigned int *idx_r)
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen unsigned int i, count;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen for (i = 0; i < count; i++) {
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (strcmp(userdbs[i]->iface->name, driver) == 0 &&
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenuserdb_preinit(pool_t pool, const char *driver, const char *args)
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen static unsigned int auth_userdb_id = 0;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen unsigned int idx;
de12ff295bb3d0873b4dced5840612cbacd635efTimo Sirainen i_fatal("Unknown userdb driver '%s'", driver);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen i_fatal("Support not compiled in for userdb driver '%s'",
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen if (iface->preinit == NULL && iface->init == NULL && *args != '\0')
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen i_fatal("userdb %s: No args are supported: %s", driver, args);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen userdb = p_new(pool, struct userdb_module, 1);
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen if (userdb->iface->init != NULL && userdb->init_refcount == 0)
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenvoid userdb_deinit(struct userdb_module *userdb)
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainen unsigned int idx;
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainen if (userdb_find(userdb->iface->name, userdb->args, &idx) == NULL)
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid userdbs_generate_md5(unsigned char md5[MD5_RESULTLEN])
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen unsigned int i, count;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen for (i = 0; i < count; i++) {
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen md5_update(&ctx, &userdbs[i]->id, sizeof(userdbs[i]->id));
367c05967091a2cbfce59b7f274f55b1a0f9e8c9Timo Sirainen md5_update(&ctx, userdbs[i]->args, strlen(userdbs[i]->args));
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenextern struct userdb_module_interface userdb_prefetch;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenextern struct userdb_module_interface userdb_static;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenextern struct userdb_module_interface userdb_passwd;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenextern struct userdb_module_interface userdb_passwd_file;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenextern struct userdb_module_interface userdb_vpopmail;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenextern struct userdb_module_interface userdb_ldap;
287ba82a8da3eaa473b5735d4eeac2fb4c5d8117Timo Sirainenextern struct userdb_module_interface userdb_sql;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenextern struct userdb_module_interface userdb_nss;
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainenextern struct userdb_module_interface userdb_checkpassword;