1 /* @(#) $Id: ./src/addagent/main.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
15 #include "manage_agents.h"
21 printf("\nOSSEC HIDS %s: Manage agents.\n", ARGV0);
22 printf("Available options:\n");
23 printf("\t-h This help message.\n");
24 printf("\t-V Display OSSEC version.\n");
25 printf("\t-l List available agents.\n");
26 printf("\t-e <id> Extracts key for an agent (Manager only).\n");
27 printf("\t-i <id> Import authentication key (Agent only).\n");
28 printf("\t-f <file> Bulk generate client keys from file. (Manager only).\n\n");
37 printf(BANNER, __name, __version);
40 printf(BANNER_CLIENT);
49 /* Clean shutdown on kill */
50 void manage_shutdown()
52 /* Checking if restart message is necessary */
68 int main(int argc, char **argv)
72 int c = 0, cmdlist = 0;
73 char *cmdexport = NULL;
74 char *cmdimport = NULL;
78 char *dir = DEFAULTDIR;
79 char *group = GROUPGLOBAL;
84 /* Setting the name */
88 while((c = getopt(argc, argv, "Vhle:i:f:")) != -1){
101 ErrorExit("%s: You can't export keys on an agent", ARGV0);
104 ErrorExit("%s: -e needs an argument",ARGV0);
109 ErrorExit("%s: You can't import keys on the manager.", ARGV0);
112 ErrorExit("%s: -i needs an argument",ARGV0);
117 ErrorExit("%s: You can't bulk generate keys on an agent.", ARGV0);
120 ErrorExit("%s: -f needs an argument",ARGV0);
122 printf("Bulk load file: %s\n", cmdbulk);
136 /* Getting currently time */
138 restart_necessary = 0;
142 /* Getting the group name */
143 gid = Privsep_GetGroup(group);
146 ErrorExit(USER_ERROR, ARGV0, "", group);
150 /* Setting the group */
151 if(Privsep_SetGroup(gid) < 0)
153 ErrorExit(SETGID_ERROR, ARGV0, group);
157 /* Chrooting to the default directory */
158 if(Privsep_Chroot(dir) < 0)
160 ErrorExit(CHROOT_ERROR, ARGV0, dir);
164 /* Inside chroot now */
168 /* Starting signal handler */
169 StartSIG2(ARGV0, manage_shutdown);
175 list_agents(cmdlist);
185 k_extract(cmdexport);
202 /* Get ACTION from the environment. If ACTION is specified,
203 * we must set leave_s = 1 to ensure that the loop will end */
204 user_msg = getenv("OSSEC_ACTION");
205 if (user_msg == NULL) {
206 user_msg = read_from_user();
212 /* All the allowed actions */
243 printf("\n ** Invalid Action ** \n\n");
256 /* Checking if restart message is necessary */
257 if(restart_necessary)
259 printf(MUST_RESTART);