userdb-vpopmail.c revision b42f37ae6f65ed986315b6885568d32115e589b1
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2002-2003 Timo Sirainen */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen/* Thanks to Courier-IMAP for showing how the vpopmail API should be used */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen#if defined(PASSDB_VPOPMAIL) || defined(USERDB_VPOPMAIL)
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstruct vqpasswd *vpopmail_lookup_vqp(struct auth_request *request,
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch /* vpop_user must be zero-filled or parse_email() leaves an
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen extra character after the user name. we'll fill vpop_domain
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen as well just to be sure... */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (parse_email(request->user, vpop_user, vpop_domain,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen "parse_email() failed");
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_request_log_info(request, "vpopmail", "unknown user");
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainenstatic void vpopmail_lookup(struct auth_request *auth_request,
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen char vpop_user[VPOPMAIL_LIMIT], vpop_domain[VPOPMAIL_LIMIT];
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen vpw = vpopmail_lookup_vqp(auth_request, vpop_user, vpop_domain);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* we have to get uid/gid separately, because the gid field in
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen struct vqpasswd isn't really gid at all but just some flags... */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (vget_assign(vpop_domain, NULL, 0, &uid, &gid) == NULL) {
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_request_log_info(auth_request, "vpopmail",
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (vpw->pw_dir == NULL || vpw->pw_dir[0] == '\0') {
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* user's homedir doesn't exist yet, create it */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_request_log_info(auth_request, "vpopmail",
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen "pw_dir isn't set, creating");
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen if (make_user_dir(vpop_user, vpop_domain, uid, gid) == NULL) {
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_request_log_error(auth_request, "vpopmail",
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen "make_user_dir(%s, %s) failed",
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen /* get the user again so pw_dir is visible */
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_stream_reply_add(reply, NULL, vpw->pw_name);
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_stream_reply_add(reply, "uid", dec2str(uid));
02c75e04c6ff80726bb59e3ea34a7995ad1f6f7cTimo Sirainen auth_stream_reply_add(reply, "gid", dec2str(gid));
8ccdf195768afdfbc32088d7be77dfca7dddd829Stephan Bosch auth_stream_reply_add(reply, "home", vpw->pw_dir);