/* $OSSEC, client-config.c, v0.1, 2005/04/01, Daniel B. Cid$ */ /* Copyright (C) 2003-2006 Daniel B. Cid * All right 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 2) as published by the FSF - Free Software * Foundation */ #include "shared.h" #include "client-config.h" #include "os_net/os_net.h" int Read_Client(XML_NODE node, void *d1, void *d2) { int i = 0; /* XML definitions */ char *xml_client_ip = "server-ip"; char *xml_client_hostname = "server-hostname"; char *xml_client_port = "port"; char *xml_ar_disabled = "disable-active-response"; agent *logr; logr = (agent *)d1; logr->execdq = 0; while(node[i]) { if(!node[i]->element) { merror(XML_ELEMNULL, ARGV0); return(OS_INVALID); } else if(!node[i]->content) { merror(XML_VALUENULL, ARGV0, node[i]->element); return(OS_INVALID); } /* Getting server ip */ else if(strcmp(node[i]->element,xml_client_ip) == 0) { os_strdup(node[i]->content, logr->rip); if(OS_IsValidIP(logr->rip, NULL) != 1) { merror(INVALID_IP, ARGV0, logr->rip); return(OS_INVALID); } } else if(strcmp(node[i]->element,xml_client_hostname) == 0) { /* We only attempt to read the hostname if the ip is not set */ if(logr->rip) { merror(AG_USINGIP, ARGV0, logr->rip); } else { char *s_ip; s_ip = OS_GetHost(node[i]->content, 5); if(s_ip) { if(OS_IsValidIP(s_ip, NULL) != 1) { merror(INVALID_IP, ARGV0, logr->rip); } else { logr->rip = s_ip; } } else { merror(AG_INV_HOST, ARGV0, node[i]->content); } } } else if(strcmp(node[i]->element,xml_client_port) == 0) { if(!OS_StrIsNum(node[i]->content)) { merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content); return(OS_INVALID); } logr->port = atoi(node[i]->content); if(logr->port <= 0 || logr->port > 65535) { merror(PORT_ERROR, ARGV0, logr->port); return(OS_INVALID); } } else if(strcmp(node[i]->element,xml_ar_disabled) == 0) { if(strcmp(node[i]->content, "yes") == 0) logr->execdq = -1; else if(strcmp(node[i]->content, "no") == 0) logr->execdq = 0; else { merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content); return(OS_INVALID); } } else { merror(XML_INVELEM, ARGV0, node[i]->element); return(OS_INVALID); } i++; } if(!logr->rip) { return(OS_INVALID); } return(0); } /* EOF */