<commit_before>/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "master-interface.h"
#include "mail-storage-service.h"
#include "lda-settings.h"
#include "lmtp-settings.h"
#include "client.h"
#include "main.h"

#include <stdlib.h>
#include <unistd.h>

#define LMTP_MASTER_FIRST_LISTEN_FD 3

#define IS_STANDALONE() \
        (getenv(MASTER_UID_ENV) == NULL)

struct mail_storage_service_multi_ctx *multi_service;

static void client_connected(const struct master_service_connection *conn)
{
	struct client *client;
	void **sets;

	client = client_create(conn->fd, conn->fd);
	client->remote_ip = conn->remote_ip;
	client->remote_port = conn->remote_port;

	sets = master_service_settings_get_others(master_service);
	client->set = sets[1];
	client->lmtp_set = sets[2];

	(void)net_getsockname(conn->fd, &client->local_ip, &client->local_port);
}

static void main_init(void)
{
	if (IS_STANDALONE())
		(void)client_create(STDIN_FILENO, STDOUT_FILENO);
}

static void main_deinit(void)
{
	clients_destroy();
}

int main(int argc, char *argv[])
{
	const struct setting_parser_info *set_roots[] = {
		&lda_setting_parser_info,
		&lmtp_setting_parser_info,
		NULL
	};
	enum master_service_flags service_flags = 0;
	enum mail_storage_service_flags storage_service_flags =
		MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT |
		MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;

	if (IS_STANDALONE()) {
		service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
			MASTER_SERVICE_FLAG_STD_CLIENT;
	}

	master_service = master_service_init("lmtp", service_flags,
					     &argc, &argv, NULL);
	if (master_getopt(master_service) > 0)
		return FATAL_DEFAULT;

	multi_service = mail_storage_service_multi_init(master_service,
							set_roots,
							storage_service_flags);
	restrict_access_allow_coredumps(TRUE);

	main_init();
	master_service_run(master_service, client_connected);

	main_deinit();
	mail_storage_service_multi_deinit(&multi_service);
	master_service_deinit(&master_service);
	return 0;
}
<commit_msg>lmtp: Fixed crashing caused by recent API changes.<commit_after>/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "array.h"
#include "ioloop.h"
#include "restrict-access.h"
#include "fd-close-on-exec.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "master-interface.h"
#include "mail-storage-service.h"
#include "lda-settings.h"
#include "lmtp-settings.h"
#include "client.h"
#include "main.h"

#include <stdlib.h>
#include <unistd.h>

#define LMTP_MASTER_FIRST_LISTEN_FD 3

#define IS_STANDALONE() \
        (getenv(MASTER_UID_ENV) == NULL)

struct mail_storage_service_multi_ctx *multi_service;

static void client_connected(const struct master_service_connection *conn)
{
	struct client *client;
	void **sets;

	client = client_create(conn->fd, conn->fd);
	client->remote_ip = conn->remote_ip;
	client->remote_port = conn->remote_port;

	sets = master_service_settings_get_others(master_service);
	client->set = sets[1];
	client->lmtp_set = sets[2];

	(void)net_getsockname(conn->fd, &client->local_ip, &client->local_port);
}

static void main_init(void)
{
	if (IS_STANDALONE())
		(void)client_create(STDIN_FILENO, STDOUT_FILENO);
}

static void main_deinit(void)
{
	clients_destroy();
}

int main(int argc, char *argv[])
{
	const struct setting_parser_info *set_roots[] = {
		&lda_setting_parser_info,
		&lmtp_setting_parser_info,
		NULL
	};
	enum master_service_flags service_flags = 0;
	enum mail_storage_service_flags storage_service_flags =
		MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT |
		MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;

	if (IS_STANDALONE()) {
		service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
			MASTER_SERVICE_FLAG_STD_CLIENT;
	}

	master_service = master_service_init("lmtp", service_flags,
					     &argc, &argv, NULL);
	if (master_getopt(master_service) > 0)
		return FATAL_DEFAULT;
	master_service_init_finish(master_service);

	multi_service = mail_storage_service_multi_init(master_service,
							set_roots,
							storage_service_flags);
	restrict_access_allow_coredumps(TRUE);

	main_init();
	master_service_run(master_service, client_connected);

	main_deinit();
	mail_storage_service_multi_deinit(&multi_service);
	master_service_deinit(&master_service);
	return 0;
}

{'fraction_non_alphanumeric': 0.11653297682709447, 'fraction_numerical': 0.006238859180035651, 'mean_word_length': 6.20545746388443, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1017274', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1644, 'n_words': 286}