bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenberger#include "pop3-common.h"
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen#include "ioloop.h"
1b04762685272a53643ac2179939537a44c7c044Timo Sirainen#include "buffer.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "istream.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "ostream.h"
dfa2201c6ac8ddb2d2798dee15662cfe774e644eMartti Rannanjärvi#include "path-util.h"
1b04762685272a53643ac2179939537a44c7c044Timo Sirainen#include "base64.h"
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen#include "str.h"
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen#include "process-title.h"
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen#include "restrict-access.h"
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen#include "settings-parser.h"
1b04762685272a53643ac2179939537a44c7c044Timo Sirainen#include "master-service.h"
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen#include "master-login.h"
a9ba65037107e370c126d2b7e8c6e3f2a4aafd23Timo Sirainen#include "master-interface.h"
00f5efa3156ab6a0b4f21e8c703d0eb816cf3091Timo Sirainen#include "var-expand.h"
01758d8aaa05940397c8210af52d7f45a5b676aeTimo Sirainen#include "mail-error.h"
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen#include "mail-user.h"
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek#include "mail-namespace.h"
1b04762685272a53643ac2179939537a44c7c044Timo Sirainen#include "mail-storage-service.h"
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
4dbe08e1f7f1271299ada9338ff5015367efd0b7Timo Sirainen#include <stdio.h>
4dbe08e1f7f1271299ada9338ff5015367efd0b7Timo Sirainen#include <unistd.h>
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen#define IS_STANDALONE() \
d482079eb385cd071bbc9637cacee225e4aff968Timo Sirainen (getenv(MASTER_IS_PARENT_ENV) == NULL)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainenstatic bool verbose_proctitle = FALSE;
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainenstatic struct mail_storage_service_ctx *storage_service;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic struct master_login *master_login = NULL;
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainenpop3_client_created_func_t *hook_client_created = NULL;
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainenpop3_client_created_func_t *
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainenpop3_client_created_hook_set(pop3_client_created_func_t *new_hook)
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen{
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen pop3_client_created_func_t *old_hook = hook_client_created;
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen hook_client_created = new_hook;
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen return old_hook;
6f2e601fa36133320aa88258106be46a175a0e53Timo Sirainen}
8f1d14e3ada93a6d6ee64f73c6e6ae2364d8eba1Timo Sirainen
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainenvoid pop3_refresh_proctitle(void)
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen{
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen struct client *client;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen string_t *title = t_str_new(128);
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen if (!verbose_proctitle)
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen return;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_append_c(title, '[');
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen switch (pop3_client_count) {
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen case 0:
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_append(title, "idling");
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen break;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen case 1:
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen client = pop3_clients;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_append(title, client->user->username);
60670187b0dd0e7f23f99a58feab11b862ad77acStephan Bosch if (client->user->conn.remote_ip != NULL) {
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_append_c(title, ' ');
60670187b0dd0e7f23f99a58feab11b862ad77acStephan Bosch str_append(title,
60670187b0dd0e7f23f99a58feab11b862ad77acStephan Bosch net_ip2addr(client->user->conn.remote_ip));
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen }
3c6a7ca2d3ed89dd999cc6885220097777090791Timo Sirainen if (client->destroyed)
3c6a7ca2d3ed89dd999cc6885220097777090791Timo Sirainen str_append(title, " (deinit)");
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen break;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen default:
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_printfa(title, "%u connections", pop3_client_count);
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen break;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen }
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen str_append_c(title, ']');
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen process_title_set(str_c(title));
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen}
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenstatic void pop3_die(void)
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen{
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen /* do nothing. pop3 connections typically die pretty quick anyway. */
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen}
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic void client_add_input(struct client *client, const buffer_t *buf)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen{
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct ostream *output;
f9ef36afc131626754716d6f4874a2ad04da0ac4Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (buf != NULL && buf->used > 0) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (!i_stream_add_data(client->input, buf->data, buf->used))
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen i_panic("Couldn't add client input to stream");
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen }
cd94aeaa294f7cc507206b4b2075852f00e14d61Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen output = client->output;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen o_stream_ref(output);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen o_stream_cork(output);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen (void)client_handle_input(client);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen o_stream_uncork(output);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen o_stream_unref(&output);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen}
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainenstatic int
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainenclient_create_from_input(const struct mail_storage_service_input *input,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek int fd_in, int fd_out, struct client **client_r,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek const char **error_r)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen{
01758d8aaa05940397c8210af52d7f45a5b676aeTimo Sirainen const char *lookup_error_str =
348d897426ff46ae23aaa432aff0087ce4d034d5Timo Sirainen "-ERR [SYS/TEMP] "MAIL_ERRSTR_CRITICAL_MSG"\r\n";
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen struct mail_storage_service_user *user;
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen struct mail_user *mail_user;
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen struct pop3_settings *set;
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen const char *errstr;
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen if (mail_storage_service_lookup_next(storage_service, input,
01758d8aaa05940397c8210af52d7f45a5b676aeTimo Sirainen &user, &mail_user, error_r) <= 0) {
f87938eab9249ad84681f4fa747aab7b9a719670Timo Sirainen if (write(fd_out, lookup_error_str, strlen(lookup_error_str)) < 0) {
f87938eab9249ad84681f4fa747aab7b9a719670Timo Sirainen /* ignored */
f87938eab9249ad84681f4fa747aab7b9a719670Timo Sirainen }
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen return -1;
01758d8aaa05940397c8210af52d7f45a5b676aeTimo Sirainen }
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen restrict_access_allow_coredumps(TRUE);
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen set = mail_storage_service_user_get_set(user)[1];
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen if (set->verbose_proctitle)
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen verbose_proctitle = TRUE;
8846e6eed6177a39b662f4f1ebf9b84ad1f0b7ecTimo Sirainen
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen if (settings_var_expand(&pop3_setting_parser_info, set,
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen mail_user->pool, mail_user_var_expand_table(mail_user),
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen &errstr) <= 0) {
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen *error_r = t_strdup_printf("Failed to expand settings: %s", errstr);
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen mail_user_unref(&mail_user);
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen mail_storage_service_user_unref(&user);
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen return -1;
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen }
c13ec2148cc43cb36f61e781f2514705f563cf47Timo Sirainen
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek *client_r = client_create(fd_in, fd_out, input->session_id,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek mail_user, user, set);
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek return 0;
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek}
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipekstatic int lock_session(struct client *client)
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek{
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek int ret;
6616907d9668d9df7bacbd863d439a31084b3d3cJosef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek i_assert(client->user->namespaces != NULL);
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek i_assert(client->set->pop3_lock_session);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if ((ret = pop3_lock_session(client)) <= 0) {
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek client_send_line(client, ret < 0 ?
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek "-ERR [SYS/TEMP] Failed to create POP3 session lock." :
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek "-ERR [IN-USE] Mailbox is locked by another POP3 session.");
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek client_destroy(client, "Couldn't lock POP3 session");
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek return -1;
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek }
0f0bf444b82bbc8c9c269a1580f37274121ce5f2Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek return 0;
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek}
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek#define MSG_BYE_INTERNAL_ERROR "-ERR "MAIL_ERRSTR_CRITICAL_MSG
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipekstatic int init_namespaces(struct client *client, bool already_logged_in)
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek{
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek const char *error;
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek /* finish initializing the user (see comment in main()) */
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek if (mail_namespaces_init(client->user, &error) < 0) {
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek if (!already_logged_in)
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek client_send_line(client, MSG_BYE_INTERNAL_ERROR);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek i_error("%s", error);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek client_destroy(client, error);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek return -1;
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek }
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek i_assert(client->inbox_ns == NULL);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek client->inbox_ns = mail_namespace_find_inbox(client->user->namespaces);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek i_assert(client->inbox_ns != NULL);
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek return 0;
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek}
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipekstatic void add_input(struct client *client,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek const buffer_t *input_buf)
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek{
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek const char *error;
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek /*
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * RFC 1939 requires that the session lock gets acquired before the
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * positive response is sent to the client indicating a transition
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * to the TRANSACTION state.
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek *
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * Since the session lock is stored under the INBOX's storage
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * directory, the locking code requires that the namespaces are
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * initialized first.
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek *
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * If the system administrator configured dovecot to not use session
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * locks, we can send back the positive response before the
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * potentially long-running namespace initialization occurs. This
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * avoids the client possibly timing out during authentication due
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek * to storage initialization taking too long.
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek */
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (client->set->pop3_lock_session) {
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (init_namespaces(client, FALSE) < 0)
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek return; /* no need to propagate an error */
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (lock_session(client) < 0)
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek return; /* no need to propagate an error */
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (!IS_STANDALONE())
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek client_send_line(client, "+OK Logged in.");
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek } else {
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (!IS_STANDALONE())
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek client_send_line(client, "+OK Logged in.");
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek if (init_namespaces(client, TRUE) < 0)
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek return; /* no need to propagate an error */
07470e90d392d4bbb77c8f75b852d4497bb9a571Josef 'Jeff' Sipek }
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek if (client_init_mailbox(client, &error) < 0) {
def59847005dd515d35fe67df57abe016095d5a1Timo Sirainen i_error("%s", error);
def59847005dd515d35fe67df57abe016095d5a1Timo Sirainen client_destroy(client, error);
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek return;
def59847005dd515d35fe67df57abe016095d5a1Timo Sirainen }
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek client_add_input(client, input_buf);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen}
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
124e615e2949883473e30950a15a563feef26406Timo Sirainenstatic void main_stdio_run(const char *username)
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen{
6616907d9668d9df7bacbd863d439a31084b3d3cJosef 'Jeff' Sipek struct client *client;
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen struct mail_storage_service_input input;
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen buffer_t *input_buf;
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen const char *value, *error, *input_base64;
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&input);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen input.module = input.service = "pop3";
124e615e2949883473e30950a15a563feef26406Timo Sirainen input.username = username != NULL ? username : getenv("USER");
cef2be5fb553b05f421f86c1ef497f0dc29d069eTimo Sirainen if (input.username == NULL && IS_STANDALONE())
cef2be5fb553b05f421f86c1ef497f0dc29d069eTimo Sirainen input.username = getlogin();
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (input.username == NULL)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen i_fatal("USER environment missing");
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen if ((value = getenv("IP")) != NULL)
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (void)net_addr2ip(value, &input.remote_ip);
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen if ((value = getenv("LOCAL_IP")) != NULL)
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (void)net_addr2ip(value, &input.local_ip);
1b04762685272a53643ac2179939537a44c7c044Timo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen input_base64 = getenv("CLIENT_INPUT");
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen input_buf = input_base64 == NULL ? NULL :
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen t_base64_decode_str(input_base64);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen if (client_create_from_input(&input, STDIN_FILENO, STDOUT_FILENO,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek &client, &error) < 0)
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen i_fatal("%s", error);
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek add_input(client, input_buf);
6616907d9668d9df7bacbd863d439a31084b3d3cJosef 'Jeff' Sipek /* client may be destroyed now */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen}
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic void
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipeklogin_client_connected(const struct master_login_client *login_client,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const char *username, const char *const *extra_fields)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen{
6616907d9668d9df7bacbd863d439a31084b3d3cJosef 'Jeff' Sipek struct client *client;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct mail_storage_service_input input;
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch enum mail_auth_request_flags flags = login_client->auth_req.flags;
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen const char *error;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen buffer_t input_buf;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&input);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen input.module = input.service = "pop3";
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek input.local_ip = login_client->auth_req.local_ip;
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek input.remote_ip = login_client->auth_req.remote_ip;
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch input.local_port = login_client->auth_req.local_port;
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch input.remote_port = login_client->auth_req.remote_port;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen input.username = username;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen input.userdb_fields = extra_fields;
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek input.session_id = login_client->session_id;
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch if ((flags & MAIL_AUTH_REQUEST_FLAG_CONN_SECURED) != 0)
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch input.conn_secured = TRUE;
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch if ((flags & MAIL_AUTH_REQUEST_FLAG_CONN_SSL_SECURED) != 0)
211caf3c233d562b0c8137e5eefae3cb1ef13003Stephan Bosch input.conn_ssl_secured = TRUE;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek buffer_create_from_const_data(&input_buf, login_client->data,
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek login_client->auth_req.data_size);
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek if (client_create_from_input(&input, login_client->fd, login_client->fd,
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek &client, &error) < 0) {
813009c4303c095ed66a6a01c110b5cfe84ea3c3Josef 'Jeff' Sipek int fd = login_client->fd;
4307c886579381dbb1897ea1388ae6978c96f560Timo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen i_error("%s", error);
4307c886579381dbb1897ea1388ae6978c96f560Timo Sirainen i_close_fd(&fd);
6667f4006484bcaf9ab8fd03b97a7a3ae84ce0d5Timo Sirainen master_service_client_connection_destroyed(master_service);
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek return;
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen }
11b8ec1586ee7c54c42fdbdf207576b06bb47b90Josef 'Jeff' Sipek add_input(client, &input_buf);
6616907d9668d9df7bacbd863d439a31084b3d3cJosef 'Jeff' Sipek /* client may be destroyed now */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen}
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainenstatic void login_client_failed(const struct master_login_client *client,
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen const char *errormsg)
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen{
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen const char *msg;
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen
348d897426ff46ae23aaa432aff0087ce4d034d5Timo Sirainen msg = t_strdup_printf("-ERR [SYS/TEMP] %s\r\n", errormsg);
747c5d36868aa738b64ceedc87cda169aa1dbe96Timo Sirainen if (write(client->fd, msg, strlen(msg)) < 0) {
747c5d36868aa738b64ceedc87cda169aa1dbe96Timo Sirainen /* ignored */
747c5d36868aa738b64ceedc87cda169aa1dbe96Timo Sirainen }
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen}
3b22894b8805b186c73d8b754001e8d7e944be85Timo Sirainen
db693bf6fcae96d834567f1782257517b7207655Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen{
6469403946bdf147886daba5ee8de07516c32238Pascal Volk /* when running standalone, we shouldn't even get here */
6469403946bdf147886daba5ee8de07516c32238Pascal Volk i_assert(master_login != NULL);
6469403946bdf147886daba5ee8de07516c32238Pascal Volk
6469403946bdf147886daba5ee8de07516c32238Pascal Volk master_service_client_connection_accept(conn);
6469403946bdf147886daba5ee8de07516c32238Pascal Volk master_login_add(master_login, conn->fd);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen}
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainenint main(int argc, char *argv[])
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen{
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen static const struct setting_parser_info *set_roots[] = {
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen &pop3_setting_parser_info,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen NULL
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen };
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen struct master_login_settings login_set;
838d6a4751c3fbe17c3ec45c0e109629c4156815Timo Sirainen enum master_service_flags service_flags =
838d6a4751c3fbe17c3ec45c0e109629c4156815Timo Sirainen MASTER_SERVICE_FLAG_SEND_STATS;
646817f0cfb39b0e0eb545900f1566b76a851b20Timo Sirainen enum mail_storage_service_flags storage_service_flags = 0;
2812f5744f44ffb070bb6f8bede8dcaa04fe6337Timo Sirainen const char *username = NULL, *auth_socket_path = "auth-master";
124e615e2949883473e30950a15a563feef26406Timo Sirainen int c;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch i_zero(&login_set);
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen login_set.postlogin_timeout_secs = MASTER_POSTLOGIN_TIMEOUT_DEFAULT;
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (IS_STANDALONE() && getuid() == 0 &&
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen net_getpeername(1, NULL, NULL) == 0) {
348d897426ff46ae23aaa432aff0087ce4d034d5Timo Sirainen printf("-ERR [SYS/PERM] pop3 binary must not be started from "
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen "inetd, use pop3-login instead.\n");
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen return 1;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen }
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (IS_STANDALONE()) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen MASTER_SERVICE_FLAG_STD_CLIENT;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen } else {
3ba9a079592f46e94ce846e5aa80e4d479cd5e41Timo Sirainen service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen }
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek /*
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek * We include MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES so that the
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek * mail_user initialization is fast and we can quickly send back the
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek * OK response to LOGIN/AUTHENTICATE. Otherwise we risk a very slow
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek * namespace initialization to cause client timeouts on login.
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek */
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES;
bd5cf4556e8a5ffd0b40dbbf404f25a2e840b2d2Josef 'Jeff' Sipek
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen master_service = master_service_init("pop3", service_flags,
2812f5744f44ffb070bb6f8bede8dcaa04fe6337Timo Sirainen &argc, &argv, "a:t:u:");
124e615e2949883473e30950a15a563feef26406Timo Sirainen while ((c = master_getopt(master_service)) > 0) {
124e615e2949883473e30950a15a563feef26406Timo Sirainen switch (c) {
2812f5744f44ffb070bb6f8bede8dcaa04fe6337Timo Sirainen case 'a':
2812f5744f44ffb070bb6f8bede8dcaa04fe6337Timo Sirainen auth_socket_path = optarg;
2812f5744f44ffb070bb6f8bede8dcaa04fe6337Timo Sirainen break;
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen case 't':
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen if (str_to_uint(optarg, &login_set.postlogin_timeout_secs) < 0 ||
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen login_set.postlogin_timeout_secs == 0)
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen i_fatal("Invalid -t parameter: %s", optarg);
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen break;
124e615e2949883473e30950a15a563feef26406Timo Sirainen case 'u':
124e615e2949883473e30950a15a563feef26406Timo Sirainen storage_service_flags |=
124e615e2949883473e30950a15a563feef26406Timo Sirainen MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
124e615e2949883473e30950a15a563feef26406Timo Sirainen username = optarg;
124e615e2949883473e30950a15a563feef26406Timo Sirainen break;
124e615e2949883473e30950a15a563feef26406Timo Sirainen default:
124e615e2949883473e30950a15a563feef26406Timo Sirainen return FATAL_DEFAULT;
124e615e2949883473e30950a15a563feef26406Timo Sirainen }
124e615e2949883473e30950a15a563feef26406Timo Sirainen }
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi const char *error;
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi if (t_abspath(auth_socket_path, &login_set.auth_socket_path, &error) < 0) {
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi i_fatal("t_abspath(%s) failed: %s", auth_socket_path, error);
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi }
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi if (argv[optind] != NULL) {
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi if (t_abspath(argv[optind], &login_set.postlogin_socket_path, &error) < 0) {
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi i_fatal("t_abspath(%s) failed: %s", argv[optind], error);
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi }
b1c85a1f889a5e71f491e320bdac95df3c9fe550Martti Rannanjärvi }
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen login_set.callback = login_client_connected;
53dff078a5f49e9d28d6c81d3437755e27526e3eTimo Sirainen login_set.failure_callback = login_client_failed;
7f4bcbb9f2d97745a12d301b9ee276200ac58605Timo Sirainen if (!IS_STANDALONE())
7f4bcbb9f2d97745a12d301b9ee276200ac58605Timo Sirainen master_login = master_login_init(master_service, &login_set);
1d3b9fce06b466bcf64f9ab7b622f3a6e4e939baTimo Sirainen
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen master_service_set_die_callback(master_service, pop3_die);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen storage_service =
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen mail_storage_service_init(master_service,
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen set_roots, storage_service_flags);
d6b3cfd855c0eebed68be50d3111de1b5a6afeb0Timo Sirainen master_service_init_finish(master_service);
7f4bcbb9f2d97745a12d301b9ee276200ac58605Timo Sirainen /* NOTE: login_set.*_socket_path are now invalid due to data stack
7f4bcbb9f2d97745a12d301b9ee276200ac58605Timo Sirainen having been freed */
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen /* fake that we're running, so we know if client was destroyed
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen while handling its initial input */
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen io_loop_set_running(current_ioloop);
573731df7d9b2ebb9028311a6c33b338dd2dd34dTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (IS_STANDALONE()) {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen T_BEGIN {
124e615e2949883473e30950a15a563feef26406Timo Sirainen main_stdio_run(username);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen } T_END;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen } else {
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen io_loop_set_running(current_ioloop);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen }
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (io_loop_is_running(current_ioloop))
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen master_service_run(master_service, client_connected);
64c7bca60b07c3652f3071913f56c6029d6deae4Timo Sirainen clients_destroy_all();
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen if (master_login != NULL)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen master_login_deinit(&master_login);
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen mail_storage_service_deinit(&storage_service);
4d4d6d4745682790c20d759ba93dbea46b812c5dTimo Sirainen master_service_deinit(&master_service);
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen return 0;
548f87789cf9865572b7b86f7be5a9bbfa132f3fTimo Sirainen}