1 /* @(#) $Id: syscheck_update.c,v 1.16 2009/06/24 18:53:10 dcid Exp $ */
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 3) as published by the FSF - Free Software
13 #include "addagent/manage_agents.h"
17 #define ARGV0 "syscheck_update"
23 printf("\nOSSEC HIDS %s: Updates the integrity check database.\n", ARGV0);
24 printf("Available options:\n");
25 printf("\t-h This help message.\n");
26 printf("\t-l List available agents.\n");
27 printf("\t-a Update syscheck database for all agents.\n");
28 printf("\t-u <id> Update syscheck database for a specific agent.\n");
29 printf("\t-u local Update syscheck database locally.\n\n");
35 int main(int argc, char **argv)
37 char *dir = DEFAULTDIR;
38 char *group = GROUPGLOBAL;
44 /* Setting the name */
54 /* Getting the group name */
55 gid = Privsep_GetGroup(group);
56 uid = Privsep_GetUser(user);
59 ErrorExit(USER_ERROR, ARGV0, user, group);
63 /* Setting the group */
64 if(Privsep_SetGroup(gid) < 0)
66 ErrorExit(SETGID_ERROR,ARGV0, group);
70 /* Chrooting to the default directory */
71 if(Privsep_Chroot(dir) < 0)
73 ErrorExit(CHROOT_ERROR, ARGV0, dir);
77 /* Inside chroot now */
81 /* Setting the user */
82 if(Privsep_SetUser(uid) < 0)
84 ErrorExit(SETUID_ERROR, ARGV0, user);
88 if(strcmp(argv[1], "-h") == 0)
92 else if(strcmp(argv[1], "-l") == 0)
94 printf("\nOSSEC HIDS %s: Updates the integrity check database.",
96 print_agents(0, 0, 0);
100 else if(strcmp(argv[1], "-u") == 0)
104 printf("\n** Option -u requires an extra argument\n");
108 else if(strcmp(argv[1], "-a") == 0)
111 struct dirent *entry;
113 sys_dir = opendir(SYSCHECK_DIR);
116 ErrorExit("%s: Unable to open: '%s'", ARGV0, SYSCHECK_DIR);
119 while((entry = readdir(sys_dir)) != NULL)
122 char full_path[OS_MAXSTR +1];
124 /* Do not even attempt to delete . and .. :) */
125 if((strcmp(entry->d_name,".") == 0)||
126 (strcmp(entry->d_name,"..") == 0))
131 snprintf(full_path, OS_MAXSTR,"%s/%s", SYSCHECK_DIR, entry->d_name);
133 fp = fopen(full_path, "w");
138 if(entry->d_name[0] == '.')
145 printf("\n** Integrity check database updated.\n\n");
150 printf("\n** Invalid option '%s'.\n", argv[1]);
156 if(strcmp(argv[2],"local") == 0)
158 char final_dir[1024];
160 snprintf(final_dir, 1020, "/%s/syscheck", SYSCHECK_DIR);
162 fp = fopen(final_dir, "w");
170 /* Deleting cpt file */
171 snprintf(final_dir, 1020, "/%s/.syscheck.cpt", SYSCHECK_DIR);
173 fp = fopen(final_dir, "w");
178 /* unlink(final_dir); */
181 /* external agents */
189 i = OS_IsAllowedID(&keys, argv[2]);
192 printf("\n** Invalid agent id '%s'.\n", argv[2]);
196 /* Deleting syscheck */
197 delete_syscheck(keys.keyentries[i]->name,keys.keyentries[i]->ip->ip,0);
200 printf("\n** Integrity check database updated.\n\n");