userdb-vpopmail.c revision 7bafda1813454621e03615e83d55bccfa7cc56bd
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen/* Thanks to Courier-IMAP for showing how the vpopmail API should be used */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen#if defined(PASSDB_VPOPMAIL) || defined(USERDB_VPOPMAIL)
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstruct vqpasswd *vpopmail_lookup_vqp(struct auth_request *request,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* vpop_user must be zero-filled or parse_email() leaves an
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen extra character after the user name. we'll fill vpop_domain
f6d57a2c182f63cd52819f0abb3c3d9f828afe19Timo Sirainen as well just to be sure... */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen if (parse_email(request->user, vpop_user, vpop_domain,
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "parse_email() failed");
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "lookup user=%s domain=%s",
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen auth_request_log_info(request, "vpopmail", "unknown user");
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic const char *
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenuserdb_vpopmail_get_quota(const char *template, const char *vpop_str)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen tab = var_expand_table_build('q', format_maildirquota(vpop_str), '\0');
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainenstatic void vpopmail_lookup(struct auth_request *auth_request,
cd83124e5d070a016c590bb0b1096d7828c7b6adTimo Sirainen struct userdb_module *_module = auth_request->userdb->userdb;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen char vpop_user[VPOPMAIL_LIMIT], vpop_domain[VPOPMAIL_LIMIT];
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen vpw = vpopmail_lookup_vqp(auth_request, vpop_user, vpop_domain);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen callback(USERDB_RESULT_USER_UNKNOWN, auth_request);
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen /* we have to get uid/gid separately, because the gid field in
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen struct vqpasswd isn't really gid at all but just some flags... */
e07bf3772a2bc075de4915ad0961beb8d083c22dTimo Sirainen if (vget_assign(vpop_domain, NULL, 0, &uid, &gid) == NULL) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen auth_request_log_info(auth_request, "vpopmail",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen /* update the last login only when we're really */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen if (vpw->pw_dir == NULL || vpw->pw_dir[0] == '\0') {
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen /* user's homedir doesn't exist yet, create it */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen auth_request_log_info(auth_request, "vpopmail",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen "pw_dir isn't set, creating");
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen if (make_user_dir(vpop_user, vpop_domain, uid, gid) == NULL) {
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen auth_request_log_error(auth_request, "vpopmail",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen "make_user_dir(%s, %s) failed",
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen /* get the user again so pw_dir is visible */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen auth_request_set_userdb_field(auth_request, "uid", dec2str(uid));
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen auth_request_set_userdb_field(auth_request, "gid", dec2str(gid));
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen auth_request_set_userdb_field(auth_request, "home", vpw->pw_dir);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen quota = userdb_vpopmail_get_quota(module->quota_template_value,
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainenvpopmail_preinit(struct auth_userdb *auth_userdb, const char *args)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen const char *const *tmp, *p;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen module = p_new(pool, struct vpopmail_userdb_module, 1);
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen for (tmp = t_strsplit(args, " "); *tmp != NULL; tmp++) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen module->module.cache_key = p_strdup(pool, *tmp + 10);
cbc61fcb33b370d049c16a3c44568b4deb4e2b33Timo Sirainen else if (strncmp(*tmp, "quota_template=", 15) == 0) {
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen "quota_template missing '='");
ce3faaaaab3e2d45b023396287e02f88e5c76e74Timo Sirainen module->quota_template_value = p_strdup(pool, p + 1);
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen i_fatal("userdb vpopmail: Unknown setting: %s", *tmp);
3e7565a7b39694bcdf448d8eb2a7f0774733297bTimo Sirainenstruct userdb_module_interface userdb_vpopmail = {