X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fremoted%2Fremoted.c;fp=src%2Fremoted%2Fremoted.c;h=dd6cd1a018fcd004c141da47916c406610ec15f0;hp=0800f1cc72695878ae87509ffb032c8d8eb8f28d;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/remoted/remoted.c b/src/remoted/remoted.c old mode 100755 new mode 100644 index 0800f1c..dd6cd1a --- a/src/remoted/remoted.c +++ b/src/remoted/remoted.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/remoted/remoted.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -8,47 +5,33 @@ * and/or modify it under the terms of the GNU General Public * License (version 2) as published by the FSF - Free Software * Foundation. - * - * License details at the LICENSE file included with OSSEC or - * online at: http://www.ossec.net/en/licensing.html */ - - -/* remote daemon. - * Listen to remote packets and forward them to the analysis - * system +/* remote daemon + * Listen to remote packets and forward them to the analysis system */ - #include "shared.h" #include "os_net/os_net.h" - #include "remoted.h" +/* Global variables */ +keystore keys; +remoted logr; -/** void HandleRemote(int position, int uid) v0.2 2005/11/09 - * Handle remote connections - * v0.2, 2005/11/09 - * v0.1, 2004/7/30 - */ +/* Handle remote connections */ void HandleRemote(int position, int uid) { /* If syslog connection and allowips is not defined, exit */ - if(logr.conn[position] == SYSLOG_CONN) - { - if(logr.allowips == NULL) - { + if (logr.conn[position] == SYSLOG_CONN) { + if (logr.allowips == NULL) { ErrorExit(NO_SYSLOG, ARGV0); - } - else - { + } else { os_ip **tmp_ips; tmp_ips = logr.allowips; - while(*tmp_ips) - { + while (*tmp_ips) { verbose("%s: Remote syslog allowed from: '%s'", ARGV0, (*tmp_ips)->ip); tmp_ips++; @@ -56,65 +39,48 @@ void HandleRemote(int position, int uid) } } - /* Bind TCP */ - if(logr.proto[position] == TCP_PROTO) - { - if((logr.sock = - OS_Bindporttcp(logr.port[position],logr.lip[position], logr.ipv6[position])) < 0) - { + if (logr.proto[position] == IPPROTO_TCP) { + logr.sock = 0; + logr.netinfo = OS_Bindporttcp(logr.port[position], logr.lip[position]); + if (logr.netinfo->status < 0) { ErrorExit(BIND_ERROR, ARGV0, logr.port[position]); } - } - else - { - /* Using UDP. Fast, unreliable.. perfect */ - if((logr.sock = - OS_Bindportudp(logr.port[position], logr.lip[position], logr.ipv6[position])) < 0) - { + } else { + /* Using UDP. Fast, unreliable... perfect */ + logr.sock = 0; + logr.netinfo = OS_Bindportudp(logr.port[position], logr.lip[position]); + if (logr.netinfo->status < 0) { ErrorExit(BIND_ERROR, ARGV0, logr.port[position]); } } - - - /* Revoking the privileges */ - if(Privsep_SetUser(uid) < 0) - { - ErrorExit(SETUID_ERROR,ARGV0, REMUSER); + /* Revoke privileges */ + if (Privsep_SetUser(uid) < 0) { + ErrorExit(SETUID_ERROR, ARGV0, REMUSER, errno, strerror(errno)); } - - /* Creating PID */ - if(CreatePID(ARGV0, getpid()) < 0) - { - ErrorExit(PID_ERROR,ARGV0); + /* Create PID */ + if (CreatePID(ARGV0, getpid()) < 0) { + ErrorExit(PID_ERROR, ARGV0); } - /* Start up message */ verbose(STARTUP_MSG, ARGV0, (int)getpid()); - - /* If Secure connection, deal with it */ - if(logr.conn[position] == SECURE_CONN) - { + /* If secure connection, deal with it */ + if (logr.conn[position] == SECURE_CONN) { HandleSecure(); } - else if(logr.proto[position] == TCP_PROTO) + else if (logr.proto[position] == IPPROTO_TCP) { HandleSyslogTCP(); } /* If not, deal with syslog */ - else - { + else { HandleSyslog(); } - - return; } - -/* EOF */