main.c revision 39802a0699533868bf6054d73265b1ac99c225f5
b5ab29780f74cf88212a547ebbe3b6bc0cb867c5Stephan Bosch/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvistatic const struct setting_parser_info *set_roots[] = {
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvistatic enum mail_storage_service_flags storage_service_flags = 0;
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvivoid (*hook_client_created)(struct client **client) = NULL;
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvistatic void client_add_input(struct client *client, const buffer_t *buf)
7ebda61d3fd228451530ca8faa33380105230ebeAki Tuomi const char *tag;
7ebda61d3fd228451530ca8faa33380105230ebeAki Tuomi unsigned int data_pos;
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi /* IMAPLOGINTAG environment is compatible with mailfront */
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi "* PREAUTH [CAPABILITY ",
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi /* client doesn't seem to understand tagged capabilities. send
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi untagged instead and hope that it works. */
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi client_send_line(client, t_strconcat("* CAPABILITY ",
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi str_c(client->capability_string), NULL));
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi client_send_line(client, t_strconcat(tag, " OK Logged in", NULL));
7ebda61d3fd228451530ca8faa33380105230ebeAki Tuomi str_c(client->capability_string), "] Logged in", NULL));
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvimain_stdio_init_user(const struct imap_settings *set, struct mail_user *user)
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi input_buf = input_base64 == NULL ? NULL :
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainen client = client_create(STDIN_FILENO, STDOUT_FILENO, user, set);
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainenstatic void main_stdio_run(void)
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainen if (input.username == NULL && IS_STANDALONE())
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainen mail_user = mail_storage_service_init_user(master_service,
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi set = mail_storage_service_get_settings(master_service);
7ebda61d3fd228451530ca8faa33380105230ebeAki Tuomi master_service_set_die_with_master(master_service, TRUE);
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi /* fake that we're running, so we know if client was destroyed
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi while handling its initial input */
7ebda61d3fd228451530ca8faa33380105230ebeAki Tuomilogin_client_connected(const struct master_login_client *client,
b28403dc4da6ee942ff18315596b43d4c4e9b7bdMartti Rannanjärvi const char *username, const char *const *extra_fields)
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainen i_error("Can't handle more than one connection currently");
4ee65ee399f701f94adfe40489a87bdf5edca316Josef 'Jeff' Sipek i_error("login client: Username missing from auth reply");
4ee65ee399f701f94adfe40489a87bdf5edca316Josef 'Jeff' Sipek mail_user = mail_storage_service_init_user(master_service,
d7a2f56cd0e550a92cb160b346f33a84b0daa75eTimo Sirainen set = mail_storage_service_get_settings(master_service);
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi master_service_set_die_with_master(master_service, TRUE);
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi /* fake that we're running, so we know if client was destroyed
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi while handling its initial input */
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi buffer_create_const_data(&input_buf, client->data,
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi imap_client = client_create(client->fd, client->fd, mail_user, set);
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomistatic void client_connected(const struct master_service_connection *conn)
dfe2b5d36666dfc941821dadf59267d28ff58ff5Aki Tuomi /* running standalone, we shouldn't even get here */
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen printf("* BAD [ALERT] imap binary must not be started from "
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen "inetd, use imap-login instead.\n");
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen master_service = master_service_init("imap", service_flags, argc, argv);
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen if (!master_service_parse_option(master_service, c, optarg))
71acd1d082704ebabd034d3e73110b39fa5b7ef2Timo Sirainen /* plugins may want to add commands, so this needs to be called early */
796beea86bcdc92e4ba2f4865414a951b1717e5cTimo Sirainen master_login = master_login_init("auth-master",