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
12 /* Functions to handle the configuration files
17 #include "agentlessd-config.h"
20 int Read_CAgentless(XML_NODE node, void *config, void *config2)
22 int i = 0,j = 0,s = 0;
25 char *xml_lessd_server = "host";
26 char *xml_lessd_port = "port";
27 char *xml_lessd_type = "type";
28 char *xml_lessd_frequency = "frequency";
29 char *xml_lessd_state = "state";
30 char *xml_lessd_command = "run_command";
31 char *xml_lessd_options = "arguments";
34 agentlessd_config *lessd_config = (agentlessd_config *)config;
37 /* Getting any configured entry. */
38 if(lessd_config->entries)
40 while(lessd_config->entries[s])
45 /* Allocating the memory for the config. */
46 os_realloc(lessd_config->entries, (s + 2) * sizeof(agentlessd_entries *),
47 lessd_config->entries);
48 os_calloc(1, sizeof(agentlessd_entries), lessd_config->entries[s]);
49 lessd_config->entries[s + 1] = NULL;
52 /* Zeroing the elements. */
53 lessd_config->entries[s]->server = NULL;
54 lessd_config->entries[s]->command = NULL;
55 lessd_config->entries[s]->options = "";
56 lessd_config->entries[s]->type = NULL;
57 lessd_config->entries[s]->frequency = 86400;
58 lessd_config->entries[s]->state = 0;
59 lessd_config->entries[s]->current_state = 0;
60 lessd_config->entries[s]->port = 0;
61 lessd_config->entries[s]->error_flag = 0;
64 /* Reading the XML. */
69 merror(XML_ELEMNULL, ARGV0);
72 else if(!node[i]->content)
74 merror(XML_VALUENULL, ARGV0, node[i]->element);
77 else if(strcmp(node[i]->element, xml_lessd_frequency) == 0)
79 if(!OS_StrIsNum(node[i]->content))
81 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
85 lessd_config->entries[s]->frequency = atoi(node[i]->content);
87 else if(strcmp(node[i]->element, xml_lessd_port) == 0)
89 if(!OS_StrIsNum(node[i]->content))
91 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
95 lessd_config->entries[s]->port = atoi(node[i]->content);
97 else if(strcmp(node[i]->element, xml_lessd_server) == 0)
99 char s_content[1024 +1];
100 s_content[1024] = '\0';
102 /* Getting any configured entry. */
104 if(lessd_config->entries[s]->server)
106 while(lessd_config->entries[s]->server[j])
110 os_realloc(lessd_config->entries[s]->server, (j + 2) *
112 lessd_config->entries[s]->server);
113 if(strncmp(node[i]->content, "use_su ", 7) == 0)
115 snprintf(s_content, 1024, "s%s", node[i]->content +7);
117 else if(strncmp(node[i]->content, "use_sudo ", 9) == 0)
119 snprintf(s_content, 1024, "o%s", node[i]->content +9);
123 snprintf(s_content, 1024, " %s", node[i]->content);
127 lessd_config->entries[s]->server[j]);
128 lessd_config->entries[s]->server[j + 1] = NULL;
130 else if(strcmp(node[i]->element, xml_lessd_type) == 0)
132 char script_path[1024 +1];
134 script_path[1024] = '\0';
135 snprintf(script_path, 1024, "%s/%s", AGENTLESSDIRPATH,
138 if(File_DateofChange(script_path) <= 0)
140 merror("%s: ERROR: Unable to find '%s' at '%s'.",
141 ARGV0, node[i]->content, AGENTLESSDIRPATH);
142 merror(XML_VALUEERR,ARGV0, node[i]->element, node[i]->content);
145 os_strdup(node[i]->content, lessd_config->entries[s]->type);
147 else if(strcmp(node[i]->element, xml_lessd_command) == 0)
149 os_strdup(node[i]->content, lessd_config->entries[s]->command);
151 else if(strcmp(node[i]->element, xml_lessd_options) == 0)
153 os_strdup(node[i]->content, lessd_config->entries[s]->options);
155 else if(strcmp(node[i]->element, xml_lessd_state) == 0)
157 if(strcmp(node[i]->content, "periodic") == 0)
159 lessd_config->entries[s]->state |= LESSD_STATE_PERIODIC;
161 else if(strcmp(node[i]->content, "stay_connected") == 0)
163 lessd_config->entries[s]->state |= LESSD_STATE_CONNECTED;
165 else if(strcmp(node[i]->content, "periodic_diff") == 0)
167 lessd_config->entries[s]->state |= LESSD_STATE_PERIODIC;
168 lessd_config->entries[s]->state |= LESSD_STATE_DIFF;
172 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
178 merror(XML_INVELEM, ARGV0, node[i]->element);
185 /* We must have at least one entry set */
186 if(!lessd_config->entries[s]->server ||
187 !lessd_config->entries[s]->state ||
188 !lessd_config->entries[s]->type)
190 merror(XML_INV_MISSOPTS, ARGV0);
195 if((lessd_config->entries[s]->state == LESSD_STATE_PERIODIC) &&
196 !lessd_config->entries[s]->frequency)
198 merror(XML_INV_MISSFREQ, ARGV0);