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