X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fremoted%2Fremoted.c;h=dd6cd1a018fcd004c141da47916c406610ec15f0;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=559b8b454900224aea33853fb9454da0137303b2;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/remoted/remoted.c b/src/remoted/remoted.c old mode 100755 new mode 100644 index 559b8b4..dd6cd1a --- a/src/remoted/remoted.c +++ b/src/remoted/remoted.c @@ -1,119 +1,86 @@ -/* @(#) $Id: remoted.c,v 1.34 2009/06/24 18:53:07 dcid Exp $ */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * 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++; } } } - - /* Bind TCP */ - if(logr.proto[position] == TCP_PROTO) - { - if((logr.sock = - OS_Bindporttcp(logr.port[position],logr.lip[position])) < 0) - { + /* Bind TCP */ + 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])) < 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); - } - - - /* Creating PID */ - if(CreatePID(ARGV0, getpid()) < 0) - { - ErrorExit(PID_ERROR,ARGV0); + /* Revoke privileges */ + if (Privsep_SetUser(uid) < 0) { + ErrorExit(SETUID_ERROR, ARGV0, REMUSER, errno, strerror(errno)); } + /* 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 */