1 /* @(#) $Id: ./src/shared/read-agents.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
14 #include "read-agents.h"
15 #include "os_net/os_net.h"
18 /* Free the agent list in memory
20 void free_agents(char **agent_list)
28 if(agent_list[i] == NULL)
42 /* Print syscheck attributes. */
43 #define sk_strchr(x,y,z) z = strchr(x, y); if(z == NULL) return(0); else { *z = '\0'; z++; }
44 int _do_print_attrs_syscheck(char *prev_attrs, char *attrs, int csv_output,
45 int is_win, int number_of_changes)
47 char *p_size, *p_perm, *p_uid, *p_gid, *p_md5, *p_sha1;
48 char *size, *perm, *uid, *gid, *md5, *sha1;
53 /* a deleted file has no attributes */
54 if(strcmp(attrs, "-1") == 0)
56 printf("File deleted.\n");
60 /* Setting each value. */
62 sk_strchr(size, ':', perm);
63 sk_strchr(perm, ':', uid);
64 sk_strchr(uid, ':', gid);
65 sk_strchr(gid, ':', md5);
66 sk_strchr(md5, ':', sha1);
75 if(prev_attrs && (strcmp(prev_attrs, "-1") == 0))
77 printf("File restored. ");
81 printf("File changed. ");
83 sk_strchr(p_size, ':', p_perm);
84 sk_strchr(p_perm, ':', p_uid);
85 sk_strchr(p_uid, ':', p_gid);
86 sk_strchr(p_gid, ':', p_md5);
87 sk_strchr(p_md5, ':', p_sha1);
91 printf("File added to the database. ");
95 /* Fixing number of changes. */
96 if(prev_attrs && !number_of_changes)
98 number_of_changes = 1;
102 if(number_of_changes)
104 switch(number_of_changes)
107 printf("- 1st time modified.\n");
110 printf("- 2nd time modified.\n");
113 printf("- 3rd time modified.\n");
116 printf("- Being ignored (3 or more changes).\n");
126 perm_int = atoi(perm);
127 snprintf(perm_str, 35,
128 "%c%c%c%c%c%c%c%c%c",
129 (perm_int & S_IRUSR)? 'r' : '-',
130 (perm_int & S_IWUSR)? 'w' : '-',
132 (perm_int & S_ISUID)? 's' :
133 (perm_int & S_IXUSR)? 'x' : '-',
136 (perm_int & S_IRGRP)? 'r' : '-',
137 (perm_int & S_IWGRP)? 'w' : '-',
139 (perm_int & S_ISGID)? 's' :
140 (perm_int & S_IXGRP)? 'x' : '-',
143 (perm_int & S_IROTH)? 'r' : '-',
144 (perm_int & S_IWOTH)? 'w' : '-',
145 (perm_int & S_ISVTX)? 't' :
146 (perm_int & S_IXOTH)? 'x' : '-');
149 printf("Integrity checking values:\n");
150 printf(" Size:%s%s\n", (strcmp(size,p_size) == 0)? " ": " >", size);
153 printf(" Perm:%s%s\n", (strcmp(perm,p_perm) == 0)? " ": " >", perm_str);
154 printf(" Uid: %s%s\n", (strcmp(uid,p_uid) == 0)? " ": " >", uid);
155 printf(" Gid: %s%s\n", (strcmp(gid,p_gid) == 0)? " ": " >", gid);
157 printf(" Md5: %s%s\n", (strcmp(md5,p_md5) == 0)? " ": " >", md5);
158 printf(" Sha1:%s%s\n", (strcmp(sha1,p_sha1) == 0)? " ": " >", sha1);
161 /* Fixing entries. */
173 /* Print information about a specific file. */
174 int _do_print_file_syscheck(FILE *fp, char *fname,
175 int update_counter, int csv_output)
180 char read_day[24 +1];
181 char buf[OS_MAXSTR + 1];
188 buf[OS_MAXSTR] = '\0';
192 /* If the compilation failed, we don't need to free anything */
193 if(!OSMatch_Compile(fname, ®, 0))
195 printf("\n** ERROR: Invalid file name: '%s'\n", fname);
200 /* Creating list with files. */
201 files_list = OSStore_Create();
204 OSMatch_FreePattern(®);
209 /* Getting initial position. */
210 if(fgetpos(fp, &init_pos) != 0)
212 printf("\n** ERROR: fgetpos failed.\n");
217 while(fgets(buf, OS_MAXSTR, fp) != NULL)
219 if(buf[0] == '!' || buf[0] == '#' || buf[0] == '+')
221 int number_changes = 0;
222 time_t change_time = 0;
223 char *changed_file_name;
230 fgetpos(fp, &init_pos);
234 /* Removing new line. */
235 buf[strlen(buf) -1] = '\0';
238 /* with update counter, we only modify the last entry. */
239 if(update_counter && buf[0] == '#')
241 fgetpos(fp, &init_pos);
246 /* Checking number of changes. */
254 else if(buf[2] == '?')
260 changed_attrs = buf + 3;
263 changed_file_name = strchr(changed_attrs, '!');
264 if(!changed_file_name)
266 fgetpos(fp, &init_pos);
271 /* Getting time of change. */
272 changed_file_name[-1] = '\0';
274 change_time = (time_t)atoi(changed_file_name);
276 changed_file_name = strchr(changed_file_name, ' ');
280 /* Checking if the name should be printed. */
281 if(!OSMatch_Execute(changed_file_name, strlen(changed_file_name),
284 fgetpos(fp, &init_pos);
292 /* Reset the values. */
295 if(fsetpos(fp, &init_pos) != 0)
297 printf("\n** ERROR: fsetpos failed (unable to update "
302 if(update_counter == 2)
304 if(fprintf(fp, "!!?") <= 0)
306 printf("\n** ERROR: fputs failed (unable to update "
314 if(fprintf(fp, "!++") <= 0)
316 printf("\n** ERROR: fputs failed (unable to update "
322 printf("\n**Counter updated for file '%s'\n\n",
328 tm_time = localtime(&change_time);
329 strftime(read_day, 23, "%Y %h %d %T", tm_time);
332 printf("\n%s,%d - %s\n", read_day, number_changes,
335 printf("%s,%s,%d\n", read_day, changed_file_name,
339 prev_attrs = OSStore_Get(files_list, changed_file_name);
343 os_strdup(changed_attrs, new_attrs);
344 _do_print_attrs_syscheck(prev_attrs, changed_attrs,
346 changed_file_name[0] == '/'?0:1,
349 free(files_list->cur_node->data);
350 files_list->cur_node->data = new_attrs;
357 os_strdup(changed_attrs, new_attrs);
358 os_strdup(changed_file_name, new_name);
359 OSStore_Put(files_list, new_name, new_attrs);
360 _do_print_attrs_syscheck(NULL,
361 changed_attrs, csv_output,
362 changed_file_name[0] == '/'?0:1,
366 fgetpos(fp, &init_pos);
372 printf("\n** No entries found.\n");
374 OSMatch_FreePattern(®);
381 /* Print syscheck db (of modified files. */
382 int _do_print_syscheck(FILE *fp, int all_files, int csv_output)
387 char read_day[24 +1];
388 char saved_read_day[24 +1];
389 char buf[OS_MAXSTR + 1];
391 buf[OS_MAXSTR] = '\0';
393 saved_read_day[0] = '\0';
394 saved_read_day[24] = '\0';
396 while(fgets(buf, OS_MAXSTR, fp) != NULL)
398 if(buf[0] == '!' || buf[0] == '#')
400 int number_changes = 0;
401 time_t change_time = 0;
402 char *changed_file_name;
408 /* Removing new line. */
409 buf[strlen(buf) -1] = '\0';
412 /* Checking number of changes. */
420 else if(buf[2] == '?')
427 changed_file_name = strchr(buf +3, '!');
428 if(!changed_file_name)
435 /* Getting time of change. */
437 change_time = atoi(changed_file_name);
439 changed_file_name = strchr(changed_file_name, ' ');
442 tm_time = localtime(&change_time);
443 strftime(read_day, 23, "%Y %h %d", tm_time);
444 if(strcmp(read_day, saved_read_day) != 0)
447 printf("\nChanges for %s:\n", read_day);
448 strncpy(saved_read_day, read_day, 23);
450 strftime(read_day, 23, "%Y %h %d %T", tm_time);
453 printf("%s,%d - %s\n", read_day, number_changes,
456 printf("%s,%s,%d\n", read_day, changed_file_name,
461 if(!f_found && !csv_output)
463 printf("\n** No entries found.\n");
470 /* Print syscheck db (of modified files. */
471 int print_syscheck(char *sk_name, char *sk_ip, char *fname, int print_registry,
472 int all_files, int csv_output, int update_counter)
477 tmp_file[512] = '\0';
482 /* Printing database */
483 snprintf(tmp_file, 512, "%s/syscheck",
486 fp = fopen(tmp_file, "r+");
489 else if(sk_ip == NULL)
491 /* Printing database */
492 snprintf(tmp_file, 512, "%s/%s->syscheck",SYSCHECK_DIR, sk_name);
494 fp = fopen(tmp_file, "r+");
497 else if(!print_registry)
499 /* Printing database */
500 snprintf(tmp_file, 512, "%s/(%s) %s->syscheck",
505 fp = fopen(tmp_file, "r+");
510 /* Printing database for the windows registry. */
511 snprintf(tmp_file, 512, "%s/(%s) %s->syscheck-registry",
516 fp = fopen(tmp_file, "r+");
524 _do_print_syscheck(fp, all_files, csv_output);
528 _do_print_file_syscheck(fp, fname, update_counter, csv_output);
538 int _do_get_rootcheckscan(FILE *fp)
541 char buf[OS_MAXSTR + 1];
543 while(fgets(buf, OS_MAXSTR, fp) != NULL)
545 tmp_str = strstr(buf, "Starting rootcheck scan");
551 s_time = (time_t)atoi(tmp_str);
557 return((int)time(NULL));
562 /* Print syscheck db (of modified files. */
563 int _do_print_rootcheck(FILE *fp, int resolved, int time_last_scan,
564 int csv_output, int show_last)
572 /* Time from the message. */
578 char read_day[24 +1];
579 char buf[OS_MAXSTR + 1];
583 char *(ig_events[]) = {"Starting rootcheck scan",
584 "Ending rootcheck scan",
585 "Starting syscheck scan",
586 "Ending syscheck scan",
589 char *(ns_events[]) = {"Application Found:",
595 buf[OS_MAXSTR] = '\0';
601 fseek(fp, 0, SEEK_SET);
608 tm_time = localtime((time_t *)&time_last_scan);
609 strftime(read_day, 23, "%Y %h %d %T", tm_time);
611 printf("\nLast scan: %s\n\n", read_day);
614 printf("\nResolved events: \n\n");
616 printf("\nOutstanding events: \n\n");
620 while(fgets(buf, OS_MAXSTR, fp) != NULL)
622 /* Removing first ! */
624 s_time = (time_t)atoi(tmp_str);
627 /* Removing new line. */
628 tmp_str = strchr(buf, '\n');
633 /* Getting initial time. */
634 tmp_str = strchr(buf + 1, '!');
639 i_time = (time_t)atoi(tmp_str);
642 /* Getting the actual message. */
643 tmp_str = strchr(tmp_str, ' ');
650 /* Checking for resolved. */
651 if(time_last_scan > (s_time + 86400))
667 /* Checking events to ignore. */
671 if(strncmp(tmp_str, ig_events[i], strlen(ig_events[i]) -1) == 0)
679 /* Checking events that are not system audit. */
683 if(strncmp(tmp_str, ns_events[i], strlen(ns_events[i]) -1) == 0)
689 tm_time = localtime((time_t *)&s_time);
690 strftime(read_day, 23, "%Y %h %d %T", tm_time);
691 tm_time = localtime((time_t *)&i_time);
692 strftime(old_day, 23, "%Y %h %d %T", tm_time);
698 printf("%s (first time detected: %s)\n", read_day, old_day);
702 printf("%s\n\n", tmp_str);
706 printf("System Audit: %s\n\n", tmp_str);
711 printf("%s,%s,%s,%s%s\n", resolved == 0?"outstanding":"resolved",
713 ns_events[i] != NULL?"":"System Audit: ",
722 if(!f_found && !csv_output)
724 printf("** No entries found.\n");
732 /* Print rootcheck db */
733 int print_rootcheck(char *sk_name, char *sk_ip, char *fname, int resolved,
734 int csv_output, int show_last)
740 tmp_file[512] = '\0';
745 /* Printing database */
746 snprintf(tmp_file, 512, "%s/rootcheck",
749 fp = fopen(tmp_file, "r+");
754 /* Printing database */
755 snprintf(tmp_file, 512, "%s/(%s) %s->rootcheck",
760 fp = fopen(tmp_file, "r+");
766 /* Getting last time of scan. */
767 ltime = _do_get_rootcheckscan(fp);
772 _do_print_rootcheck(fp, 1, ltime, csv_output, 0);
774 else if(resolved == 2)
776 _do_print_rootcheck(fp, 0, ltime, csv_output, show_last);
780 _do_print_rootcheck(fp, 1, ltime, csv_output, 0);
781 _do_print_rootcheck(fp, 0, ltime, csv_output, show_last);
796 /* Delete syscheck db */
797 int delete_syscheck(char *sk_name, char *sk_ip, int full_delete)
802 tmp_file[512] = '\0';
804 /* Deleting related files */
805 snprintf(tmp_file, 512, "%s/(%s) %s->syscheck",
810 fp = fopen(tmp_file, "w");
818 /* Deleting cpt files */
819 snprintf(tmp_file, 512, "%s/.(%s) %s->syscheck.cpt",
824 fp = fopen(tmp_file, "w");
830 /* Deleting registry entries */
831 snprintf(tmp_file, 512, "%s/(%s) %s->syscheck-registry",
836 fp = fopen(tmp_file, "w");
843 /* Deleting cpt files */
844 snprintf(tmp_file, 512, "%s/.(%s) %s->syscheck-registry.cpt",
849 fp = fopen(tmp_file, "w");
859 /* Delete rootcheck db */
860 int delete_rootcheck(char *sk_name, char *sk_ip, int full_delete)
865 tmp_file[512] = '\0';
867 /* Deleting related files */
868 snprintf(tmp_file, 512, "%s/(%s) %s->rootcheck",
873 fp = fopen(tmp_file, "w");
888 int delete_agentinfo(char *name)
894 tmp_file[512] = '\0';
897 /* Deleting agent info */
898 snprintf(tmp_file, 512, "%s/%s", AGENTINFO_DIR, name);
902 /* Deleting syscheck */
904 sk_ip = strrchr(name, '-');
912 /* Deleting syscheck */
913 delete_syscheck(sk_name, sk_ip, 1);
920 /** char *print_agent_status(int status)
921 * Prints the text representation of the agent status.
923 char *print_agent_status(int status)
925 char *status_str = "Never connected";
927 if(status == GA_STATUS_ACTIVE)
929 status_str = "Active";
931 else if(status == GA_STATUS_NACTIVE)
933 status_str = "Disconnected";
940 /* non-windows functions from now on. */
944 /** int send_msg_to_agent(int socket, char *msg)
945 * Sends a message to an agent.
946 * returns -1 on error.
948 int send_msg_to_agent(int msocket, char *msg, char *agt_id, char *exec)
951 char agt_msg[OS_SIZE_1024 +1];
953 agt_msg[OS_SIZE_1024] = '\0';
958 snprintf(agt_msg, OS_SIZE_1024,
961 (agt_id == NULL)?ALL_AGENTS_C:NONE_C,
963 (agt_id != NULL)?SPECIFIC_AGENT_C:NONE_C,
964 agt_id != NULL? agt_id: "(null)",
969 snprintf(agt_msg, OS_SIZE_1024,
970 "%s %c%c%c %s %s - %s (from_the_server) (no_rule_id)",
972 (agt_id == NULL)?ALL_AGENTS_C:NONE_C,
974 (agt_id != NULL)?SPECIFIC_AGENT_C:NONE_C,
975 agt_id != NULL? agt_id: "(null)",
981 if((rc = OS_SendUnix(msocket, agt_msg, 0)) < 0)
983 if(rc == OS_SOCKBUSY)
985 merror("%s: ERROR: Remoted socket busy.", __local_name);
989 merror("%s: ERROR: Remoted socket error.", __local_name);
991 merror("%s: Error communicating with remoted queue (%d).",
1002 /** int connect_to_remoted()
1003 * Connects to remoted to be able to send messages to the agents.
1004 * Returns the socket on success or -1 on failure.
1006 int connect_to_remoted()
1010 if((arq = StartMQ(ARQUEUE, WRITE)) < 0)
1012 merror(ARQ_ERROR, __local_name);
1023 /* Internal funtion. Extract last time of scan from rootcheck/syscheck. */
1024 int _get_time_rkscan(char *agent_name, char *agent_ip, agent_info *agt_info)
1030 /* Agent name of null, means it is the server info. */
1031 if(agent_name == NULL)
1033 snprintf(buf, 1024, "%s/rootcheck",
1038 snprintf(buf, 1024, "%s/(%s) %s->rootcheck",
1039 ROOTCHECK_DIR, agent_name, agent_ip);
1043 /* If file is not there, set to unknown. */
1044 fp = fopen(buf, "r");
1047 os_strdup("Unknown", agt_info->rootcheck_time);
1048 os_strdup("Unknown", agt_info->rootcheck_endtime);
1049 os_strdup("Unknown", agt_info->syscheck_time);
1050 os_strdup("Unknown", agt_info->syscheck_endtime);
1055 while(fgets(buf, 1024, fp) != NULL)
1057 char *tmp_str = NULL;
1059 /* Removing new line. */
1060 tmp_str = strchr(buf, '\n');
1065 tmp_str = strstr(buf, "Starting syscheck scan");
1071 s_time = (time_t)atoi(tmp_str);
1073 os_strdup(ctime(&s_time), agt_info->syscheck_time);
1075 /* Removing new line. */
1076 tmp_str = strchr(agt_info->syscheck_time, '\n');
1083 tmp_str = strstr(buf, "Ending syscheck scan");
1089 s_time = (time_t)atoi(tmp_str);
1091 os_strdup(ctime(&s_time), agt_info->syscheck_endtime);
1093 /* Removing new line. */
1094 tmp_str = strchr(agt_info->syscheck_endtime, '\n');
1102 tmp_str = strstr(buf, "Starting rootcheck scan");
1108 s_time = (time_t)atoi(tmp_str);
1110 os_strdup(ctime(&s_time), agt_info->rootcheck_time);
1112 /* Removing new line. */
1113 tmp_str = strchr(agt_info->rootcheck_time, '\n');
1120 tmp_str = strstr(buf, "Ending rootcheck scan");
1126 s_time = (time_t)atoi(tmp_str);
1128 os_strdup(ctime(&s_time), agt_info->rootcheck_endtime);
1130 /* Removing new line. */
1131 tmp_str = strchr(agt_info->rootcheck_endtime, '\n');
1140 /* Setting unknown values. */
1141 if(!agt_info->rootcheck_time)
1142 os_strdup("Unknown", agt_info->rootcheck_time);
1143 if(!agt_info->rootcheck_endtime)
1144 os_strdup("Unknown", agt_info->rootcheck_endtime);
1145 if(!agt_info->syscheck_time)
1146 os_strdup("Unknown", agt_info->syscheck_time);
1147 if(!agt_info->syscheck_endtime)
1148 os_strdup("Unknown", agt_info->syscheck_endtime);
1156 /* Internal funtion. Extract last time of scan from rootcheck/syscheck. */
1157 char *_get_agent_keepalive(char *agent_name, char *agent_ip)
1160 struct stat file_status;
1163 /* No keep alive for the server. */
1166 return(strdup("Not available"));
1169 snprintf(buf, 1024, "%s/%s-%s", AGENTINFO_DIR, agent_name, agent_ip);
1170 if(stat(buf, &file_status) < 0)
1172 return(strdup("Unknown"));
1176 return(strdup(ctime(&file_status.st_mtime)));
1181 /* Internal funtion. Extracts operating system. */
1182 int _get_agent_os(char *agent_name, char *agent_ip, agent_info *agt_info)
1188 /* Getting server info. */
1191 char *ossec_version = NULL;
1192 agt_info->os = getuname();
1193 os_strdup(__name " " __version, agt_info->version);
1196 /* Removing new line. */
1197 ossec_version = strchr(agt_info->os, '\n');
1199 *ossec_version = '\0';
1202 ossec_version = strstr(agt_info->os, " - ");
1205 *ossec_version = '\0';
1209 if(strlen(agt_info->os) > 55)
1211 agt_info->os[52] = '.';
1212 agt_info->os[53] = '.';
1213 agt_info->os[54] = '\0';
1221 snprintf(buf, 1024, "%s/%s-%s", AGENTINFO_DIR, agent_name, agent_ip);
1222 fp = fopen(buf, "r");
1225 os_strdup("Unknown", agt_info->os);
1226 os_strdup("Unknown", agt_info->version);
1231 if(fgets(buf, 1024, fp))
1233 char *ossec_version = NULL;
1235 /* Removing new line. */
1236 ossec_version = strchr(buf, '\n');
1238 *ossec_version = '\0';
1241 ossec_version = strstr(buf, " - ");
1244 *ossec_version = '\0';
1247 os_calloc(1024 +1, sizeof(char), agt_info->version);
1248 strncpy(agt_info->version, ossec_version, 1024);
1252 if(strlen(buf) > 55)
1259 os_strdup(buf, agt_info->os);
1267 os_strdup("Unknown", agt_info->os);
1268 os_strdup("Unknown", agt_info->version);
1275 /** agent_info *get_agent_info(char *agent_name, char *agent_ip)
1276 * Get information from an agent.
1278 agent_info *get_agent_info(char *agent_name, char *agent_ip)
1281 char *agent_ip_pt = NULL;
1282 char *tmp_str = NULL;
1284 agent_info *agt_info = NULL;
1286 tmp_file[512] = '\0';
1289 /* Removing the "/", since it is not present on the file. */
1290 if((agent_ip_pt = strchr(agent_ip, '/')))
1292 *agent_ip_pt = '\0';
1296 /* Allocating memory for the info structure. */
1297 agt_info = calloc(1, sizeof(agent_info));
1300 /* Zeroing the values. */
1301 agt_info->rootcheck_time = NULL;
1302 agt_info->rootcheck_endtime = NULL;
1303 agt_info->syscheck_time = NULL;
1304 agt_info->syscheck_endtime = NULL;
1305 agt_info->os = NULL;
1306 agt_info->version = NULL;
1307 agt_info->last_keepalive = NULL;
1310 /* Getting information about the OS. */
1311 _get_agent_os(agent_name, agent_ip, agt_info);
1312 _get_time_rkscan(agent_name, agent_ip, agt_info);
1313 agt_info->last_keepalive = _get_agent_keepalive(agent_name, agent_ip);
1316 /* Removing new line from keep alive. */
1317 tmp_str = strchr(agt_info->last_keepalive, '\n');
1323 /* Setting back the ip address. */
1335 /** int get_agent_status(char *agent_name, char *agent_ip)
1336 * Gets the status of an agent, based on the name/ip.
1338 int get_agent_status(char *agent_name, char *agent_ip)
1341 char *agent_ip_pt = NULL;
1343 struct stat file_status;
1345 tmp_file[512] = '\0';
1349 if(agent_name == NULL)
1351 return(GA_STATUS_ACTIVE);
1355 /* Removing the "/", since it is not present on the file. */
1356 if((agent_ip_pt = strchr(agent_ip, '/')))
1358 *agent_ip_pt = '\0';
1361 snprintf(tmp_file, 512, "%s/%s-%s", AGENTINFO_DIR, agent_name, agent_ip);
1364 /* Setting back the ip address. */
1371 if(stat(tmp_file, &file_status) < 0)
1373 return(GA_STATUS_INV);
1377 if(file_status.st_mtime > (time(0) - (3*NOTIFY_TIME + 30)))
1379 return(GA_STATUS_ACTIVE);
1382 return(GA_STATUS_NACTIVE);
1387 /* List available agents.
1389 char **get_agents(int flag)
1393 char **f_files = NULL;
1396 struct dirent *entry;
1398 /* Opening the directory given */
1399 dp = opendir(AGENTINFO_DIR);
1402 merror("%s: Error opening directory: '%s': %s ",
1410 /* Reading directory */
1411 while((entry = readdir(dp)) != NULL)
1415 tmp_file[512] = '\0';
1417 /* Just ignore . and .. */
1418 if((strcmp(entry->d_name,".") == 0) ||
1419 (strcmp(entry->d_name,"..") == 0))
1422 snprintf(tmp_file, 512, "%s/%s", AGENTINFO_DIR, entry->d_name);
1427 struct stat file_status;
1429 if(stat(tmp_file, &file_status) < 0)
1432 if(file_status.st_mtime > (time(0) - (3*NOTIFY_TIME + 30)))
1435 if(flag == GA_NOTACTIVE)
1440 if(flag == GA_ACTIVE)
1445 f_files = (char **)realloc(f_files, (f_size +2) * sizeof(char *));
1448 ErrorExit(MEM_ERROR, __local_name);
1452 /* Adding agent entry */
1453 if(flag == GA_ALL_WSTATUS)
1457 snprintf(agt_stat, sizeof(agt_stat) -1, "%s %s",
1458 entry->d_name, status == 1?"active":"disconnected");
1460 os_strdup(agt_stat, f_files[f_size]);
1464 os_strdup(entry->d_name, f_files[f_size]);
1467 f_files[f_size +1] = NULL;