1 /* @(#) $Id: main.c,v 1.15 2009/08/05 18:02:13 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
14 #include "manage_agents.h"
20 printf("\nOSSEC HIDS %s: Manage agents.\n", ARGV0);
21 printf("Available options:\n");
22 printf("\t-h This help message.\n");
23 printf("\t-V Display OSSEC version.\n");
24 printf("\t-l List available agents.\n");
25 printf("\t-e <id> Extracts key for an agent (Manager only).\n");
26 printf("\t-i <id> Import authentication key (Agent only).\n\n");
35 printf(BANNER, __name, __version);
38 printf(BANNER_CLIENT);
47 /* Clean shutdown on kill */
48 void manage_shutdown()
50 /* Checking if restart message is necessary */
66 int main(int argc, char **argv)
70 int c = 0, cmdlist = 0;
71 char *cmdexport = NULL;
72 char *cmdimport = NULL;
75 char *dir = DEFAULTDIR;
76 char *group = GROUPGLOBAL;
81 /* Setting the name */
85 while((c = getopt(argc, argv, "Vhle:i:")) != -1){
98 ErrorExit("%s: You can't export keys on an agent", ARGV0);
101 ErrorExit("%s: -e needs an argument",ARGV0);
106 ErrorExit("%s: You can't import keys on the manager.", ARGV0);
109 ErrorExit("%s: -i needs an argument",ARGV0);
124 /* Getting currently time */
126 restart_necessary = 0;
130 /* Getting the group name */
131 gid = Privsep_GetGroup(group);
134 ErrorExit(USER_ERROR, ARGV0, "", group);
138 /* Setting the group */
139 if(Privsep_SetGroup(gid) < 0)
141 ErrorExit(SETGID_ERROR, ARGV0, group);
145 /* Chrooting to the default directory */
146 if(Privsep_Chroot(dir) < 0)
148 ErrorExit(CHROOT_ERROR, ARGV0, dir);
152 /* Inside chroot now */
156 /* Starting signal handler */
157 StartSIG2(ARGV0, manage_shutdown);
163 list_agents(cmdlist);
173 k_extract(cmdexport);
185 user_msg = read_from_user();
187 /* All the allowed actions */
218 printf("\n ** Invalid Action ** \n\n");
231 /* Checking if restart message is necessary */
232 if(restart_necessary)
234 printf(MUST_RESTART);