1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
14 /* Check if syscheck is to be executed/restarted
15 * Returns 1 on success or 0 on failure (shouldn't be executed now)
17 int os_check_restart_syscheck()
19 /* If the restart is not present, return 0 */
21 if (unlink(SYSCHECK_RESTART) == -1) {
25 if (unlink(SYSCHECK_RESTART_PATH) == -1) {
33 /* Set syscheck to be restarted
34 * Returns 1 on success or 0 on failure
36 int os_set_restart_syscheck()
40 fp = fopen(SYSCHECK_RESTART, "w");
42 merror(FOPEN_ERROR, __local_name, SYSCHECK_RESTART, errno, strerror(errno));
46 fprintf(fp, "%s\n", SYSCHECK_RESTART);
52 /* Read the agent name for the current agent
53 * Returns NULL on error
55 char *os_read_agent_name()
60 debug2("%s: calling os_read_agent_name().", __local_name);
63 fp = fopen(AGENT_INFO_FILE, "r");
65 fp = fopen(AGENT_INFO_FILEP, "r");
68 /* We give 1 second for the file to be created */
73 fp = fopen(AGENT_INFO_FILE, "r");
75 fp = fopen(AGENT_INFO_FILEP, "r");
80 debug1(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
87 if (fgets(buf, 1024, fp)) {
92 len = strlen(buf) - 1;
93 while (len > 0 && buf[len] == '\n')
99 debug2("%s: os_read_agent_name returned (%s).", __local_name, ret);
108 /* Read the agent ip for the current agent
109 * Returns NULL on error
111 char *os_read_agent_ip()
116 debug2("%s: calling os_read_agent_ip().", __local_name);
118 fp = fopen(AGENT_INFO_FILE, "r");
120 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
127 if (fgets(buf, 1024, fp) && fgets(buf, 1024, fp)) {
139 /* Read the agent id for the current agent
140 * Returns NULL on error
142 char *os_read_agent_id()
147 debug2("%s: calling os_read_agent_id().", __local_name);
149 fp = fopen(AGENT_INFO_FILE, "r");
151 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
158 if (fgets(buf, 1024, fp) && fgets(buf, 1024, fp) && fgets(buf, 1024, fp)) {
170 /* Read the agent profile name for the current agent
171 * Returns NULL on error
174 * Comma separated list of strings that used to identify what type
175 * of configuration is used for this agent.
176 * The profile name is set in the agent's etc/ossec.conf file
177 * It is matched with the ossec manager's agent.conf file to read
178 * configuration only applicable to this profile name.
180 char *os_read_agent_profile()
185 debug2("%s: calling os_read_agent_profile().", __local_name);
188 fp = fopen(AGENT_INFO_FILE, "r");
190 fp = fopen(AGENT_INFO_FILEP, "r");
194 debug2("%s: Failed to open file. Errno=%d.", __local_name, errno);
195 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
202 if (fgets(buf, 1024, fp) && fgets(buf, 1024, fp) &&
203 fgets(buf, 1024, fp) && fgets(buf, 1024, fp)) {
206 /* Trim the /n and/or /r at the end of the string */
210 debug2("%s: os_read_agent_profile() = [%s]", __local_name, ret);
221 /* Write the agent info to the queue, for the other processes to read
222 * Returns 1 on success or <= 0 on failure
224 int os_write_agent_info(const char *agent_name, __attribute__((unused)) const char *agent_ip,
225 const char *agent_id, const char *cfg_profile_name)
229 fp = fopen(AGENT_INFO_FILE, "w");
231 merror(FOPEN_ERROR, __local_name, AGENT_INFO_FILE, errno, strerror(errno));
240 (cfg_profile_name) ? cfg_profile_name : "-"