bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Thanks to Courier-IMAP for showing how the vpopmail API should be used */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen#if defined(PASSDB_VPOPMAIL) || defined(USERDB_VPOPMAIL)
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainenstruct vqpasswd *vpopmail_lookup_vqp(struct auth_request *request,
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen /* vpop_user must be zero-filled or parse_email() leaves an
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen extra character after the user name. we'll fill vpop_domain
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen as well just to be sure... */
356303df200c991580bd24041996a070ad08c05eTimo Sirainen if (parse_email(request->user, vpop_user, vpop_domain,
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_info(request, AUTH_SUBSYS_DB,
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen "parse_email() failed");
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_debug(request, AUTH_SUBSYS_DB,
00bde9ae9eab9e720462bf6ec9a4dd85e88c3bbfTimo Sirainen "lookup user=%s domain=%s",
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_unknown_user(request, AUTH_SUBSYS_DB);
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomiuserdb_vpopmail_get_quota(const char *template, const char *vpop_str,
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomi if (var_expand(quota, template, tab, error_r) < 0)
3b94ff5951db4d4eddb7a80ed4e3f61207202635Timo Sirainenstatic void vpopmail_lookup(struct auth_request *auth_request,
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen struct userdb_module *_module = auth_request->userdb->userdb;
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen char vpop_user[VPOPMAIL_LIMIT], vpop_domain[VPOPMAIL_LIMIT];
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen vpw = vpopmail_lookup_vqp(auth_request, vpop_user, vpop_domain);
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen callback(USERDB_RESULT_USER_UNKNOWN, auth_request);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* we have to get uid/gid separately, because the gid field in
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen struct vqpasswd isn't really gid at all but just some flags... */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen if (vget_assign(vpop_domain, NULL, 0, &uid, &gid) == NULL) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_info(auth_request, AUTH_SUBSYS_DB,
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
e15f1d736c225c7ce6f3d08a37c1b2ae66b57c50Timo Sirainen /* update the last login only when we're really */
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen if (vpw->pw_dir == NULL || vpw->pw_dir[0] == '\0') {
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* user's homedir doesn't exist yet, create it */
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_info(auth_request, AUTH_SUBSYS_DB,
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen "pw_dir isn't set, creating");
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen if (make_user_dir(vpop_user, vpop_domain, uid, gid) == NULL) {
6135260095e1704ed6edff9d00bdfc043c11429cTimo Sirainen auth_request_log_error(auth_request, AUTH_SUBSYS_DB,
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen "make_user_dir(%s, %s) failed",
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen /* get the user again so pw_dir is visible */
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomi if (userdb_vpopmail_get_quota(module->quota_template_value,
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomi auth_request_log_error(auth_request, AUTH_SUBSYS_DB,
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomi "userdb_vpopmail_get_quota(%s, %s) failed: %s",
c6ae57a037d81f3932faead5ffb44c07b547e2f1Aki Tuomi callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request);
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen auth_request_set_userdb_field(auth_request, "uid", dec2str(uid));
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen auth_request_set_userdb_field(auth_request, "gid", dec2str(gid));
6fabfb7bbfd88d0c1de66981e52850f26067623bTimo Sirainen auth_request_set_userdb_field(auth_request, "home", vpw->pw_dir);
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainenvpopmail_preinit(pool_t pool, const char *args)
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen module = p_new(pool, struct vpopmail_userdb_module, 1);
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen for (tmp = t_strsplit(args, " "); *tmp != NULL; tmp++) {
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen else if (strncmp(*tmp, "quota_template=", 15) == 0) {
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen "quota_template missing '='");
806cb455553b71934314da98f1b4a694a3aa152eTimo Sirainen module->quota_template_value = p_strdup(pool, p + 1);
c64e714193097f841691dcfa2902c270cb47bff8Timo Sirainen } else if (strcmp(*tmp, "blocking=no") == 0) {
dd93aba1901a457346990f49c54a738947dc7128Timo Sirainen i_fatal("userdb vpopmail: Unknown setting: %s", *tmp);
b42f37ae6f65ed986315b6885568d32115e589b1Timo Sirainenstruct userdb_module_interface userdb_vpopmail = {