main.c revision 2454dfa32c93c20a8522c6ed42fe057baaac9f9a
/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
#include "login-common.h"
#include "ioloop.h"
#include "array.h"
#include "randgen.h"
#include "module-dir.h"
#include "process-title.h"
#include "restrict-access.h"
#include "restrict-process-size.h"
#include "master-auth.h"
#include "master-service.h"
#include "master-interface.h"
#include "client-common.h"
#include "access-lookup.h"
#include "anvil-client.h"
#include "auth-client.h"
#include "dsasl-client.h"
#include "master-service-ssl-settings.h"
#include "ssl-proxy.h"
#include "login-proxy.h"
#include <unistd.h>
#include <syslog.h>
struct login_access_lookup {
struct master_service_connection conn;
char **sockets, **next_socket;
struct access_lookup *access;
};
const struct login_binary *login_binary;
struct auth_client *auth_client;
struct master_auth *master_auth;
bool closing_down, login_debug;
struct anvil_client *anvil;
const char *login_rawlog_dir = NULL;
unsigned int initial_service_count;
const struct login_settings *global_login_settings;
const struct master_service_ssl_settings *global_ssl_settings;
void **global_other_settings;
const struct ip_addr *login_source_ips;
unsigned int login_source_ips_idx, login_source_ips_count;
static struct timeout *auth_client_to;
static const char *post_login_socket;
static bool shutting_down = FALSE;
static bool ssl_connections = FALSE;
static bool auth_connected_once = FALSE;
void login_refresh_proctitle(void)
{
const char *addr;
return;
if (clients_get_count() == 0) {
process_title_set("");
clients_get_count(), ssl_proxy_get_count()));
} else {
if (addr[0] != '\0') {
} else {
}
}
}
{
}
void login_client_destroyed(void)
{
}
}
static void login_die(void)
{
if (!auth_client_is_connected(auth_client)) {
/* we don't have auth client, and we might never get one */
}
}
static void
{
const struct login_settings *set;
const struct master_service_ssl_settings *ssl_set;
int fd_ssl;
void **other_sets;
} else {
if (fd_ssl == -1) {
pool_unref(&pool);
return;
}
}
if (auth_client_to != NULL)
}
{
i_error("close(client) failed: %m");
}
}
{
if (!success) {
i_info("access(%s): Client refused (rip=%s)",
} else {
lookup->next_socket++;
}
}
{
/* last one */
return;
}
}
{
char c;
int ret;
if (ret <= 0) {
i_info("access(%s): Client disconnected during lookup (rip=%s)",
} else {
/* actual input. stop listening until lookup is done. */
}
}
{
const char *access_sockets =
struct login_access_lookup *lookup;
/* log the connection's IP address in case we crash. it's of
course possible that another earlier client causes the
crash, but this is better than nothing. */
}
/* make sure we're connected (or attempting to connect) to auth */
if (*access_sockets == '\0') {
/* no access checks */
return;
}
}
{
if (connected) {
} else if (shutting_down)
else if (!auth_connected_once) {
/* auth disconnected without having ever succeeded, so the
auth process is probably misconfigured. no point in
keeping the client connections hanging. */
clients_destroy_all_reason("Disconnected: Auth process broken");
}
}
static bool anvil_reconnect_callback(void)
{
/* we got disconnected from anvil. we can't reconnect to it since we're
chrooted, so just die after we've finished handling the current
connections. */
return FALSE;
}
static const struct ip_addr *
{
const char *const *tmp;
bool skip_nonworking = FALSE;
unsigned int i, tmp_ips_count;
int ret;
if (ips_str[0] == '?') {
/* try binding to the IP immediately. if it doesn't
work, skip it. (this allows using the same config file for
all the servers.) */
ips_str++;
}
if (ret != 0) {
i_error("login_source_ips: net_gethostbyname(%s) failed: %s",
continue;
}
for (i = 0; i < tmp_ips_count; i++) {
continue;
}
}
}
static void login_load_modules(void)
{
struct module_dir_load_settings mod_set;
return;
&mod_set);
}
static void main_preinit(void)
{
unsigned int max_fds;
random_init();
/* Initialize SSL proxy so it can read certificate and private
key file. */
/* set the number of fds we want to use. it may get increased or
decreased. leave a couple of extra fds for auth sockets and such.
worst case each connection can use:
- 1 for client
- 1 for login proxy
- 2 for client-side ssl proxy
- 2 for server-side ssl proxy (with login proxy)
However, login process nowadays supports plugins, there are rawlogs
and so on. Don't enforce the fd limit anymore, but use this value
for optimizing the ioloop's fd table size.
*/
if (global_login_settings->mail_max_userip_connections > 0) {
i_fatal("Couldn't connect to anvil");
}
/* read the login_source_ips before chrooting so it can access
if (login_source_ips_count > 0) {
/* randomize the initial index in case service_count=1
(although in that case it's unlikely this setting is
even used..) */
}
if (login_debug)
if (restrict_access_get_current_chroot() == NULL) {
if (chdir("login") < 0)
i_fatal("chdir(login) failed: %m");
}
if (login_rawlog_dir != NULL &&
i_error("access(%s, wx) failed: %m - disabling rawlog",
}
}
static void main_init(const char *login_socket)
{
/* make sure we can't fork() */
FALSE);
login_binary->init();
login_proxy_init("proxy-notify");
}
static void main_deinit(void)
{
login_binary->deinit();
char **strp;
if (auth_client_to != NULL)
}
{
const char *login_socket;
int c;
"Dl:R:S");
while ((c = master_getopt(master_service)) > 0) {
switch (c) {
case 'D':
login_debug = TRUE;
break;
case 'l':
break;
case 'R':
break;
case 'S':
break;
default:
return FATAL_DEFAULT;
}
}
login_binary->preinit();
main_preinit();
main_deinit();
return 0;
}