<commit_before>/*--------------------------------------------------------------------*
 *
 * Developed by;
 *	<NAME> - http://www.wanlink.com
 *	Copyright (c) 2002 <NAME>. All Rights Reserved
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions
 *	are met:
 *	1. Redistributions of source code must retain the above copyright
 *	   notice, this list of conditions and the following disclaimer.
 *	2. Redistributions in binary form must reproduce the above copyright
 *	   notice, this list of conditions and the following disclaimer in the
 *	   documentation and/or other materials provided with the distribution.
 *	3. All advertising materials mentioning features or use of this software
 *	   must display the following acknowledgement:
 *	This product includes software developed by <NAME>.
 *	4. Neither the name <NAME> nor the names of any contributors
 *	   may be used to endorse or promote products derived from this software
 *	   without specific prior written permission.
 *	
 *	THIS SOFTWARE IS PROVIDED BY <NAME> AND ANY CONTRIBUTORS ``AS IS'' AND
 *	ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *	ARE DISCLAIMED.  IN NO EVENT SHALL <NAME> OR ANY CONTRIBUTORS BE LIABLE
 *	FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 *	DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 *	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *	LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 *	OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *	SUCH DAMAGE.
 *
 *	CVSID:  $Id: ipfwmtad.c,v 1.22 2011/10/27 18:16:53 neal Exp $
 *
 * DESCRIPTION:
 *	application:	ipfwmtad
 *	module:		main.c
 *--------------------------------------------------------------------*/

static char const cvsid[] = "@(#)$Id: ipfwmtad.c,v 1.22 2011/10/27 18:16:53 neal Exp $";

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <termios.h> 
#include <fcntl.h>
#include <string.h>
#include <syslog.h>
#include <stdarg.h>
#include <time.h>

#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <arpa/inet.h>


#include "inet.h"
#include "misc.h"
#include "ipfw_direct.h"
#include "key.h"

#ifdef SUPPORT_PAM
#include "pam.h"
#else
#include "uam.h"
#endif

typedef struct _MTAINFO
{
	long	ip;
	time_t	timeFirst;
	time_t	timeExpire;
	long	timeInterval;
	long	count;
	int	opcode;
	int	rate;
	int	update;
	int	needAdd;
	struct _MTAINFO *next;
} MTAINFO, *PMTAINFO;

typedef struct _CLIENTINFO
{
	int		authlevel;
	BIGNUM		*pchallenge;
	char		*pchallengestr;
	RSA		*pclikey;
} CLIENT, *PCLIENT;

enum { AL_NONE, AL_FULL };

char *opcodes[] = {"None\t","Add\t","Inculpate","Del\t","Blocked\t","Inculpate Blocked","Exculpate"};

enum { OPCODE_NONE, OPCODE_PENDING_ADD, OPCODE_PENDING_INCULPATE, OPCODE_PENDING_DEL, OPCODE_BLOCKED, OPCODE_INCULPATE_BLOCKED, OPCODE_PENDING_EXCULPATE, OPCODE_PENDING_FWREMOVE, OPCODE_FWREMOVED, };

int	gAction		= 0;	/* deny = 0, add = 1*/
int	gPortNum	= 25;
int	gRuleNum	= 90;
int	gDebug		= 0;
int	debugmode	= 0;
int	gSdTcp		= INVALID_SOCKET;
MTAINFO	*gpMtaInfo	= NULL;
char	*gpMtaDbFname	= "/tmp/ipfwmtad.db";
RSA	*gChildRsa	= NULL;
char	*gChildRsaPKey	= NULL;
fd_set	gChildFds;
CLIENT	gChildClients[FD_SETSIZE];

#define TIME24HOURS (60 * 60 * 24)

void MtaInfoIpfwSync(int needDelete)
{	PMTAINFO	pinfo = gpMtaInfo;
#if !defined(USEIPFWDIRECT) && defined(OS_FreeBSD)
	ipfw_startup();
#endif

	if(debugmode>1)
		printf("MtaInfoIpfwSync %s delete\n",needDelete ? "with" : "no");

#if defined(OS_FreeBSD)
	/* delete the mta rules */
	if(needDelete)
#if defined(USEIPFWDIRECT)
		ipfw_del(gRuleNum);
#else
		mlfi_systemPrintf("ipfw delete %u\n",gRuleNum);
#endif
#endif

	/* add/remove the mta rules */
	while(pinfo != NULL)
	{
		switch(pinfo->opcode)
		{
			case OPCODE_PENDING_FWREMOVE:
#ifdef OS_Linux
				mlfi_systemPrintf("iptables -D SPAMILTER -s %u.%u.%u.%u/32 -j DROP (or -j REJECT)\n"
					((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff)
					);
#endif
				pinfo->opcode = OPCODE_FWREMOVED;
				break;

			case OPCODE_INCULPATE_BLOCKED:
				/* deliberate fall thru to OPCODE_BLOCKED */
			case OPCODE_BLOCKED:
				if(pinfo->needAdd || needDelete)
				{
#if defined(OS_FreeBSD)
#if defined(USEIPFWDIRECT)
					ipfw_add(gRuleNum,pinfo->ip,gPortNum,gAction);
#else
					mlfi_systemPrintf("ipfw -q add %u deny tcp from %u.%u.%u.%u to any %u\n",gRuleNum,
						((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff),gPortNum);
#endif
#endif
#ifdef OS_Linux
				mlfi_systemPrintf("iptables -I SPAMILTER -s %u.%u.%u.%u/32 -j DROP (or -j REJECT)\n"
					((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff)
					);
#endif<commit_msg>make it compile<commit_after>/*--------------------------------------------------------------------*
 *
 * Developed by;
 *	<NAME> - http://www.wanlink.com
 *	Copyright (c) 2002 <NAME>. All Rights Reserved
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions
 *	are met:
 *	1. Redistributions of source code must retain the above copyright
 *	   notice, this list of conditions and the following disclaimer.
 *	2. Redistributions in binary form must reproduce the above copyright
 *	   notice, this list of conditions and the following disclaimer in the
 *	   documentation and/or other materials provided with the distribution.
 *	3. All advertising materials mentioning features or use of this software
 *	   must display the following acknowledgement:
 *	This product includes software developed by <NAME>.
 *	4. Neither the name <NAME> nor the names of any contributors
 *	   may be used to endorse or promote products derived from this software
 *	   without specific prior written permission.
 *	
 *	THIS SOFTWARE IS PROVIDED BY <NAME> AND ANY CONTRIBUTORS ``AS IS'' AND
 *	ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *	ARE DISCLAIMED.  IN NO EVENT SHALL <NAME> OR ANY CONTRIBUTORS BE LIABLE
 *	FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 *	DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 *	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *	LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 *	OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *	SUCH DAMAGE.
 *
 *	CVSID:  $Id: ipfwmtad.c,v 1.22 2011/10/27 18:16:53 neal Exp $
 *
 * DESCRIPTION:
 *	application:	ipfwmtad
 *	module:		main.c
 *--------------------------------------------------------------------*/

static char const cvsid[] = "@(#)$Id: ipfwmtad.c,v 1.22 2011/10/27 18:16:53 neal Exp $";

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <termios.h> 
#include <fcntl.h>
#include <string.h>
#include <syslog.h>
#include <stdarg.h>
#include <time.h>

#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <arpa/inet.h>


#include "inet.h"
#include "misc.h"
#include "ipfw_direct.h"
#include "key.h"

#ifdef SUPPORT_PAM
#include "pam.h"
#else
#include "uam.h"
#endif

typedef struct _MTAINFO
{
	long	ip;
	time_t	timeFirst;
	time_t	timeExpire;
	long	timeInterval;
	long	count;
	int	opcode;
	int	rate;
	int	update;
	int	needAdd;
	struct _MTAINFO *next;
} MTAINFO, *PMTAINFO;

typedef struct _CLIENTINFO
{
	int		authlevel;
	BIGNUM		*pchallenge;
	char		*pchallengestr;
	RSA		*pclikey;
} CLIENT, *PCLIENT;

enum { AL_NONE, AL_FULL };

char *opcodes[] = {"None\t","Add\t","Inculpate","Del\t","Blocked\t","Inculpate Blocked","Exculpate"};

enum { OPCODE_NONE, OPCODE_PENDING_ADD, OPCODE_PENDING_INCULPATE, OPCODE_PENDING_DEL, OPCODE_BLOCKED, OPCODE_INCULPATE_BLOCKED, OPCODE_PENDING_EXCULPATE, OPCODE_PENDING_FWREMOVE, OPCODE_FWREMOVED, };

int	gAction		= 0;	/* deny = 0, add = 1*/
int	gPortNum	= 25;
int	gRuleNum	= 90;
int	gDebug		= 0;
int	debugmode	= 0;
int	gSdTcp		= INVALID_SOCKET;
MTAINFO	*gpMtaInfo	= NULL;
char	*gpMtaDbFname	= "/tmp/ipfwmtad.db";
RSA	*gChildRsa	= NULL;
char	*gChildRsaPKey	= NULL;
fd_set	gChildFds;
CLIENT	gChildClients[FD_SETSIZE];

#define TIME24HOURS (60 * 60 * 24)

void MtaInfoIpfwSync(int needDelete)
{	PMTAINFO	pinfo = gpMtaInfo;
#if !defined(USEIPFWDIRECT) && defined(OS_FreeBSD)
	ipfw_startup();
#endif

	if(debugmode>1)
		printf("MtaInfoIpfwSync %s delete\n",needDelete ? "with" : "no");

#if defined(OS_FreeBSD)
	/* delete the mta rules */
	if(needDelete)
#if defined(USEIPFWDIRECT)
		ipfw_del(gRuleNum);
#else
		mlfi_systemPrintf("ipfw delete %u\n",gRuleNum);
#endif
#endif

	/* add/remove the mta rules */
	while(pinfo != NULL)
	{
		switch(pinfo->opcode)
		{
			case OPCODE_PENDING_FWREMOVE:
#ifdef OS_Linux
				mlfi_systemPrintf("iptables -D SPAMILTER -s %u.%u.%u.%u/32 -j DROP (or -j REJECT)\n",
					((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff)
					);
#endif
				pinfo->opcode = OPCODE_FWREMOVED;
				break;

			case OPCODE_INCULPATE_BLOCKED:
				/* deliberate fall thru to OPCODE_BLOCKED */
			case OPCODE_BLOCKED:
				if(pinfo->needAdd || needDelete)
				{
#if defined(OS_FreeBSD)
#if defined(USEIPFWDIRECT)
					ipfw_add(gRuleNum,pinfo->ip,gPortNum,gAction);
#else
					mlfi_systemPrintf("ipfw -q add %u deny tcp from %u.%u.%u.%u to any %u\n",gRuleNum,
						((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff),gPortNum);
#endif
#endif
#ifdef OS_Linux
				mlfi_systemPrintf("iptables -I SPAMILTER -s %u.%u.%u.%u/32 -j DROP (or -j REJECT)\n",
					((pinfo->ip&0xff000000)>>24),((pinfo->ip&0xff0000)>>16),((pinfo->ip&0xff00)>>8),(pinfo->ip&0xff)
					);
#endif
{'fraction_non_alphanumeric': 0.15148042024832856, 'fraction_numerical': 0.02425978987583572, 'mean_word_length': 3.9508274231678486, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5747409', 'n_tokens_mistral': 4279, 'n_tokens_neox': 3900, 'n_words': 1055}