bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainenstatic ARRAY(struct userdb_module_interface *) userdb_interfaces;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainenstatic ARRAY(struct userdb_module *) userdb_modules;
9d75363d3fbabc2fbc2d80f06672e3ed8965804aTimo Sirainenstatic const struct userdb_module_interface userdb_iface_deinit = {
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenstatic struct userdb_module_interface *userdb_interface_find(const char *name)
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct userdb_module_interface *const *ifaces;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen struct userdb_module_interface *iface = *ifaces;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdb_register_module(struct userdb_module_interface *iface)
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen old_iface = userdb_interface_find(iface->name);
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen if (old_iface != NULL && old_iface->lookup == NULL) {
5c99eaa4e3e07ee065580d163240b4ce95b66befTimo Sirainen /* replacing a "support not compiled in" userdb */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen i_panic("userdb_register_module(%s): Already registered",
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenvoid userdb_unregister_module(struct userdb_module_interface *iface)
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen struct userdb_module_interface *const *ifaces;
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen idx = array_foreach_idx(&userdb_interfaces, ifaces);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen i_panic("userdb_unregister_module(%s): Not registered", iface->name);
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainenuid_t userdb_parse_uid(struct auth_request *request, const char *str)
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_error(request, AUTH_SUBSYS_DB,
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainengid_t userdb_parse_gid(struct auth_request *request, const char *str)
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_error(request, AUTH_SUBSYS_DB,
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenuserdb_find(const char *driver, const char *args, unsigned int *idx_r)
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen for (i = 0; i < count; i++) {
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (strcmp(userdbs[i]->iface->name, driver) == 0 &&
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainenuserdb_preinit(pool_t pool, const struct auth_userdb_settings *set)
966cb0c1aa58578339cea6f79b4a423a851ab074Timo Sirainen /* maybe it's a plugin. try to load it. */
966cb0c1aa58578339cea6f79b4a423a851ab074Timo Sirainen auth_module_load(t_strconcat("authdb_", set->driver, NULL));
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen i_fatal("Unknown userdb driver '%s'", set->driver);
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen i_fatal("Support not compiled in for userdb driver '%s'",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen if (iface->preinit == NULL && iface->init == NULL &&
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen i_fatal("userdb %s: No args are supported: %s",
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen userdb = userdb_find(set->driver, set->args, &idx);
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen userdb = p_new(pool, struct userdb_module, 1);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (userdb->iface->init != NULL && userdb->init_refcount == 0)
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainenvoid userdb_deinit(struct userdb_module *userdb)
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen if (userdb_find(userdb->iface->name, userdb->args, &idx) == NULL)
9d75363d3fbabc2fbc2d80f06672e3ed8965804aTimo Sirainen /* make sure userdb isn't accessed again */
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvivoid userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN])
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen for (i = 0; i < count; i++) {
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen md5_update(&ctx, &userdbs[i]->id, sizeof(userdbs[i]->id));
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen md5_update(&ctx, userdbs[i]->args, strlen(userdbs[i]->args));
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_prefetch;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_static;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_passwd;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_passwd_file;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_vpopmail;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_ldap;
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenextern struct userdb_module_interface userdb_sql;
51ead2f4c04ee85615d23c453924633b9ed8a4c2Timo Sirainenextern struct userdb_module_interface userdb_checkpassword;
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainenextern struct userdb_module_interface userdb_dict;