Пример #1
0
static MsgStatus msg_is_spam(FILE *fp)
{
	struct transport trans;
	struct message m;
	gboolean is_spam = FALSE;

	if (!config.enable)
		return MSG_IS_HAM;

	transport_init(&trans);
	switch (config.transport) {
	case SPAMASSASSIN_TRANSPORT_LOCALHOST:
		trans.type = TRANSPORT_LOCALHOST;
		trans.port = config.port;
		break;
	case SPAMASSASSIN_TRANSPORT_TCP:
		trans.type = TRANSPORT_TCP;
		trans.hostname = config.hostname;
		trans.port = config.port;
		break;
	case SPAMASSASSIN_TRANSPORT_UNIX:
		trans.type = TRANSPORT_UNIX;
		trans.socketpath = config.socket;
		break;
	default:
		return MSG_IS_HAM;
	}

	if (transport_setup(&trans, flags) != EX_OK) {
		log_error(LOG_PROTOCOL, _("SpamAssassin plugin couldn't connect to spamd.\n"));
		debug_print("failed to setup transport\n");
		return MSG_FILTERING_ERROR;
	}

	m.type = MESSAGE_NONE;
	m.max_len = config.max_size * 1024;
	m.timeout = config.timeout;

	if (message_read(fileno(fp), flags, &m) != EX_OK) {
		debug_print("failed to read message\n");
		message_cleanup(&m);
		return MSG_FILTERING_ERROR;
	}

	if (message_filter(&trans, config.username, flags, &m) != EX_OK) {
		log_error(LOG_PROTOCOL, _("SpamAssassin plugin filtering failed.\n"));
		debug_print("filtering the message failed\n");
		message_cleanup(&m);
		return MSG_FILTERING_ERROR;
	}

	if (m.is_spam == EX_ISSPAM)
		is_spam = TRUE;

	message_cleanup(&m);

	return is_spam ? MSG_IS_SPAM:MSG_IS_HAM;
}
Пример #2
0
int request_worker(worker_t *worker, GError **error) {
	request_t *request = NULL;


	EXTRA_ASSERT(worker != NULL);
	EXTRA_ASSERT(worker->data.session != NULL);

	request = g_malloc0(sizeof(request_t));

	if (!read_request_from_message((message_t*)worker->data.session, request, error)) {
		GSETERROR(error, "Failed to parse message to build request");
		request_clean(request);
		return 0;
	}

	/* Free the message and put the request in session */
	message_cleanup(worker);
	worker->data.session = request;
	worker->clean = request_cleanup;
	worker->func = g_hash_table_lookup(requests, request->cmd);

	if (!worker->func) {
		GSETERROR(error, "No handler found for request [%s]", request->cmd);
		return 0;
	}

	if (!change_fd_events_in_io_scheduler(worker, EPOLLOUT, error)) {
		GSETERROR(error, "Failed to change polling event on fd %d", worker->data.fd);
		return 0;
	}

	return 1;
}
Пример #3
0
static void cleanup(void)
{
  LOG_WARNING("Terminating");

  message_post_shutdown();
  message_cleanup();

  if(group)
    select_group_destroy(group);

  if(driver_console)
    driver_console_destroy(driver_console);
  if(driver_command)
    driver_command_destroy(driver_command);
  if(driver_dns)
    driver_dns_destroy(driver_dns);
  if(driver_exec)
    driver_exec_destroy(driver_exec);
  if(driver_listener)
    driver_listener_destroy(driver_listener);
  if(driver_ping)
    driver_ping_destroy(driver_ping);

  print_memory();
}