passdb-checkpassword.c revision 51821162b1df9a8a9398b8b64ceca410b9cc3092
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2004-2010 Dovecot authors, see the included COPYING file */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainen const char *checkpassword_path, *checkpassword_reply_path;
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainenstatic struct child_wait *checkpassword_passdb_children = NULL;
863ea896fb31a16d1baec31e57650243b5547db6Timo Sirainenstatic void checkpassword_request_finish(struct chkpw_auth_request *request,
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainen struct passdb_module *_module = request->request->passdb->passdb;
4b231ca0bbe3b536acbd350101e183441ce0247aTimo Sirainen (struct checkpassword_passdb_module *)_module;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen hash_table_remove(module->clients, POINTER_CAST(request->pid));
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen if (strchr(str_c(request->input_buf), '\n') != NULL) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "checkpassword",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "LF characters in checkpassword reply");
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainencheckpassword_request_half_finish(struct chkpw_auth_request *request)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* vpopmail exit codes: */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen case 3: /* password fail / vpopmail user not found */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen case 22: /* system user shadow entry not found */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen /* standard checkpassword exit codes: */
88b8aea03a24ef7a9efc30399080487b7eb03537Timo Sirainen /* (1 is additionally defined in vpopmail for
88b8aea03a24ef7a9efc30399080487b7eb03537Timo Sirainen "pop/smtp/webmal/ imap/access denied") */
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen auth_request_log_info(request->request, "checkpassword",
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen "Login failed (status=%d)",
d9fda7e3a0fa5551547ac3e3054b837fc77f4bfbTimo Sirainen checkpassword_request_finish(request, PASSDB_RESULT_OK);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* missing input - fall through */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* checkpassword is called with wrong
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen parameters? unlikely */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen auth_request_log_error(request->request, "checkpassword",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "Child %s exited with status 2 (tried to use "
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "userdb-only checkpassword program for passdb?)",
45e62043058738e294f89504c319d852e25943ccTimo Sirainen /* temporary problem, treat as internal error */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* whatever error.. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen auth_request_log_error(request->request, "checkpassword",
d5960ce1c0adda5c9e259bc429123ebc29c60baeTimo Sirainen "Child %s exited with status %d",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void sigchld_handler(const struct child_wait_status *status,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen hash_table_lookup(module->clients, POINTER_CAST(status->pid));
bdd7a96c363346f7c38f389791be1487ca08775bTimo Sirainen switch (checkpassword_sigchld_handler(status, request)) {
4bc96ba6f1d67a90a75fa131bcd2cd508ea5a05aTimo Sirainencheckpassword_verify_plain_child(struct auth_request *request,
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen if (dup2(fd_out, 3) < 0 || dup2(fd_in, 4) < 0) {
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen auth_request_log_error(request, "checkpassword",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "dup2() failed: %m");
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen cmd = checkpassword_get_cmd(request, module->checkpassword_path,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen auth_request_log_debug(request, "checkpassword",
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* very simple argument splitting. */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainencheckpassword_verify_plain(struct auth_request *request, const char *password,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct passdb_module *_module = request->passdb->passdb;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen (struct checkpassword_passdb_module *)_module;
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct chkpw_auth_request *chkpw_auth_request;
if (pid == 0) {
static struct passdb_module *
NULL,
NULL,