1 /* @(#) $Id: ./src/remoted/syslog.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
16 #include "os_net/os_net.h"
22 /* OS_IPNotAllowed, v0.1, 2005/02/11
23 * Checks if an IP is not allowed.
25 static int OS_IPNotAllowed(char *srcip)
27 if(logr.denyips != NULL)
29 if(OS_IPFoundList(srcip, logr.denyips))
34 if(logr.allowips != NULL)
36 if(OS_IPFoundList(srcip, logr.allowips))
42 /* If the ip is not allowed, it will be denied */
47 /** void HandleSyslog() v0.2
48 * Handle syslog connections
52 char buffer[OS_SIZE_1024 +2];
53 char srcip[IPSIZE +1];
55 char *buffer_pt = NULL;
59 struct sockaddr_in peer_info;
63 /* setting peer size */
64 peer_size = sizeof(peer_info);
67 /* Initializing some variables */
68 memset(buffer, '\0', OS_SIZE_1024 +2);
71 /* Connecting to the message queue
74 if((logr.m_queue = StartMQ(DEFAULTQUEUE,WRITE)) < 0)
76 ErrorExit(QUEUE_FATAL,ARGV0, DEFAULTQUEUE);
80 /* Infinite loop in here */
83 /* Receiving message */
84 recv_b = recvfrom(logr.sock, buffer, OS_SIZE_1024, 0,
85 (struct sockaddr *)&peer_info, &peer_size);
87 /* Nothing received */
92 /* null terminating the message */
93 buffer[recv_b] = '\0';
96 /* Removing new line */
97 if(buffer[recv_b -1] == '\n')
99 buffer[recv_b -1] = '\0';
102 /* Setting the source ip */
103 strncpy(srcip, inet_ntoa(peer_info.sin_addr), IPSIZE);
104 srcip[IPSIZE] = '\0';
107 /* Removing syslog header */
110 buffer_pt = strchr(buffer+1, '>');
125 /* Checking if IP is allowed here */
126 if(OS_IPNotAllowed(srcip))
128 merror(DENYIP_WARN,ARGV0,srcip);
131 else if(SendMSG(logr.m_queue, buffer_pt, srcip,
134 merror(QUEUE_ERROR,ARGV0,DEFAULTQUEUE, strerror(errno));
135 if((logr.m_queue = StartMQ(DEFAULTQUEUE,READ)) < 0)
137 ErrorExit(QUEUE_FATAL,ARGV0,DEFAULTQUEUE);