1 /* $OSSEC, client-config.c, v0.1, 2005/04/01, Daniel B. Cid$ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
15 #include "client-config.h"
16 #include "os_net/os_net.h"
19 int Read_Client(XML_NODE node, void *d1, void *d2)
24 char *xml_client_ip = "server-ip";
25 char *xml_client_hostname = "server-hostname";
26 char *xml_local_ip = "local_ip";
27 char *xml_client_port = "port";
28 char *xml_ar_disabled = "disable-active-response";
30 char *xml_profile_name = "config-profile";
41 merror(XML_ELEMNULL, ARGV0);
44 else if(!node[i]->content)
46 merror(XML_VALUENULL, ARGV0, node[i]->element);
49 /* Getting local ip. */
50 else if(strcmp(node[i]->element, xml_local_ip) == 0)
52 os_strdup(node[i]->content, logr->lip);
53 if(OS_IsValidIP(logr->lip, NULL) != 1)
55 merror(INVALID_IP, ARGV0, logr->lip);
59 /* Getting server ip */
60 else if(strcmp(node[i]->element,xml_client_ip) == 0)
67 while(logr->rip[ip_id])
72 os_realloc(logr->rip, (ip_id + 2) * sizeof(char*), logr->rip);
73 logr->rip[ip_id] = NULL;
74 logr->rip[ip_id +1] = NULL;
76 os_strdup(node[i]->content, logr->rip[ip_id]);
77 if(OS_IsValidIP(logr->rip[ip_id], NULL) != 1)
79 merror(INVALID_IP, ARGV0, logr->rip[ip_id]);
84 else if(strcmp(node[i]->element,xml_client_hostname) == 0)
91 /* Getting last ip. */
94 while(logr->rip[ip_id])
100 os_realloc(logr->rip, (ip_id + 2) * sizeof(char*),
104 s_ip = OS_GetHost(node[i]->content, 5);
107 merror("%s: WARN: Unable to get hostname for '%s'.",
108 ARGV0, node[i]->content);
109 merror(AG_INV_HOST, ARGV0, node[i]->content);
111 os_strdup("invalid_ip", s_ip);
116 snprintf(f_ip, 127, "%s/%s", node[i]->content, s_ip);
118 os_strdup(f_ip, logr->rip[ip_id]);
119 logr->rip[ip_id +1] = NULL;
125 else if(strcmp(node[i]->element,xml_client_port) == 0)
127 if(!OS_StrIsNum(node[i]->content))
129 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
132 logr->port = atoi(node[i]->content);
134 if(logr->port <= 0 || logr->port > 65535)
136 merror(PORT_ERROR, ARGV0, logr->port);
140 else if(strcmp(node[i]->element,xml_ar_disabled) == 0)
142 if(strcmp(node[i]->content, "yes") == 0)
144 else if(strcmp(node[i]->content, "no") == 0)
148 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
153 else if(strcmp(node[i]->element,xml_profile_name) == 0)
155 /* profile name can be anything hence no validation */
156 os_strdup(node[i]->content, logr->profile);
160 merror(XML_INVELEM, ARGV0, node[i]->element);