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