userdb.c revision 9d75363d3fbabc2fbc2d80f06672e3ed8965804a
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
fa2a11210f20fb8998ed656f75e163191c8047e6Timo Sirainenstatic ARRAY_DEFINE(userdb_interfaces, struct userdb_module_interface *);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic ARRAY_DEFINE(userdb_modules, struct userdb_module *);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic const struct userdb_module_interface userdb_iface_deinit = {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic struct userdb_module_interface *userdb_interface_find(const char *name)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct userdb_module_interface *const *ifaces;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct userdb_module_interface *iface = *ifaces;
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainenvoid userdb_register_module(struct userdb_module_interface *iface)
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen old_iface = userdb_interface_find(iface->name);
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen if (old_iface != NULL && old_iface->lookup == NULL) {
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainen /* replacing a "support not compiled in" userdb */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_panic("userdb_register_module(%s): Already registered",
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainenvoid userdb_unregister_module(struct userdb_module_interface *iface)
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen struct userdb_module_interface *const *ifaces;
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen unsigned int idx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen idx = array_foreach_idx(&userdb_interfaces, ifaces);
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen i_panic("userdb_unregister_module(%s): Not registered", iface->name);
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainenuid_t userdb_parse_uid(struct auth_request *request, const char *str)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainengid_t userdb_parse_gid(struct auth_request *request, const char *str)
b34fdb68d376d85b4880da4a4bdf67ae726a381bTimo Sirainenuserdb_find(const char *driver, const char *args, unsigned int *idx_r)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int i, count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < count; i++) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (strcmp(userdbs[i]->iface->name, driver) == 0 &&
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenuserdb_preinit(pool_t pool, const char *driver, const char *args)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen static unsigned int auth_userdb_id = 0;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int idx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_fatal("Unknown userdb driver '%s'", driver);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_fatal("Support not compiled in for userdb driver '%s'",
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen if (iface->preinit == NULL && iface->init == NULL && *args != '\0')
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen i_fatal("userdb %s: No args are supported: %s", driver, args);
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainen userdb = p_new(pool, struct userdb_module, 1);
18c209a06941ef583b08b173dadfbe4571995bf9Timo Sirainen if (userdb->iface->init != NULL && userdb->init_refcount == 0)
18c209a06941ef583b08b173dadfbe4571995bf9Timo Sirainenvoid userdb_deinit(struct userdb_module *userdb)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen unsigned int idx;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (userdb_find(userdb->iface->name, userdb->args, &idx) == NULL)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* make sure userdb isn't accessed again */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid userdbs_generate_md5(unsigned char md5[MD5_RESULTLEN])
fc464e5b2b2ab4d415a5d5b90ce4475d34620a75Timo Sirainen unsigned int i, count;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (i = 0; i < count; i++) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen md5_update(&ctx, &userdbs[i]->id, sizeof(userdbs[i]->id));
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen md5_update(&ctx, userdbs[i]->args, strlen(userdbs[i]->args));
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenextern struct userdb_module_interface userdb_prefetch;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenextern struct userdb_module_interface userdb_static;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_passwd;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_passwd_file;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_vpopmail;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_ldap;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_sql;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_nss;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenextern struct userdb_module_interface userdb_checkpassword;