main.c revision c1b0fc9bde0ca3690aa71c5812406b82eb50b356
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara/* Copyright (C) 2002-2003 Timo Sirainen */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara (getenv("LOGGED_IN") == NULL && getenv("IMAPLOGINTAG") == NULL)
f14a485fcb48f77d077a14b766f0acc097093fe5jvergaraunsigned int max_keyword_length, mailbox_check_interval;
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergarastatic char log_prefix[128]; /* syslog() needs this to be permanent */
53247d28ba99538f841a13ea2cde01c3faa3ef36kenneth_sutervoid (*hook_mail_storage_created)(struct mail_storage **storage) = NULL;
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergaravoid (*hook_client_created)(struct client **client) = NULL;
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergarastatic void open_logfile(void)
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara const char *user;
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* quite a long user name, cut it */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara i_snprintf(log_prefix, sizeof(log_prefix), "imap(%s)", user);
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara i_set_failure_syslog(log_prefix, LOG_NDELAY, LOG_MAIL);
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* log to file or stderr */
4cf0e2c1065147b79e7d6ffe59e517c38cbc6bdejvergara i_set_failure_timestamp_format(getenv("LOGSTAMP"));
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergarastatic void drop_privileges(void)
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* Log file or syslog opening probably requires roots */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* Most likely needed. Have to open /dev/urandom before possible
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara chrooting. */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergarastatic void main_init(void)
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara capability_string = str_new(default_pool, sizeof(CAPABILITY_STRING)+32);
4cf0e2c1065147b79e7d6ffe59e517c38cbc6bdejvergara namespace_pool = pool_alloconly_create("namespaces", 1024);
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara client = client_create(0, 1, namespace_init(namespace_pool, user));
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* Support for mailfront */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara client_send_line(client, t_strconcat(getenv("IMAPLOGINTAG"),
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergarastatic void main_deinit(void)
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* warn about being killed because of some signal, except SIGINT (^C)
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara which is too common at least while testing :) */
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara i_warning("Killed with signal %d", lib_signal_kill);
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergaraint main(int argc __attr_unused__, char *argv[], char *envp[])
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara /* NOTE: we start rooted, so keep the code minimal until
11178d20048abeee671d0cdb2aab6dfbaa36293bjvergara restrict_access_by_env() is called */