-/* @(#) $Id$ */
+/* @(#) $Id: ./src/addagent/main.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
#include "manage_agents.h"
-
+#include <stdlib.h>
/** help **/
void helpmsg()
printf("\t-V Display OSSEC version.\n");
printf("\t-l List available agents.\n");
printf("\t-e <id> Extracts key for an agent (Manager only).\n");
- printf("\t-i <id> Import authentication key (Agent only).\n\n");
+ printf("\t-i <id> Import authentication key (Agent only).\n");
+ printf("\t-f <file> Bulk generate client keys from file. (Manager only).\n\n");
exit(1);
}
int c = 0, cmdlist = 0;
char *cmdexport = NULL;
char *cmdimport = NULL;
-
+ char *cmdbulk = NULL;
+
#ifndef WIN32
char *dir = DEFAULTDIR;
char *group = GROUPGLOBAL;
int gid;
#endif
-
+
/* Setting the name */
OS_SetName(ARGV0);
-
- while((c = getopt(argc, argv, "Vhle:i:")) != -1){
+
+ while((c = getopt(argc, argv, "Vhle:i:f:")) != -1){
switch(c){
case 'V':
print_version();
ErrorExit("%s: -i needs an argument",ARGV0);
cmdimport = optarg;
break;
+ case 'f':
+ #ifdef CLIENT
+ ErrorExit("%s: You can't bulk generate keys on an agent.", ARGV0);
+ #endif
+ if(!optarg)
+ ErrorExit("%s: -f needs an argument",ARGV0);
+ cmdbulk = optarg;
+ printf("Bulk load file: %s\n", cmdbulk);
+ break;
case 'l':
cmdlist = 1;
break;
}
}
-
-
+
+
/* Getting currently time */
time1 = time(0);
restart_necessary = 0;
-
-
- #ifndef WIN32
+
+
+ #ifndef WIN32
/* Getting the group name */
gid = Privsep_GetGroup(group);
if(gid < 0)
{
ErrorExit(USER_ERROR, ARGV0, "", group);
}
-
-
+
+
/* Setting the group */
if(Privsep_SetGroup(gid) < 0)
{
ErrorExit(SETGID_ERROR, ARGV0, group);
}
-
-
+
+
/* Chrooting to the default directory */
if(Privsep_Chroot(dir) < 0)
{
k_extract(cmdexport);
exit(0);
}
+ else if(cmdbulk)
+ {
+ k_bulkload(cmdbulk);
+ exit(0);
+ }
{
int leave_s = 0;
print_banner();
-
- user_msg = read_from_user();
-
+
+ /* Get ACTION from the environment. If ACTION is specified,
+ * we must set leave_s = 1 to ensure that the loop will end */
+ user_msg = getenv("OSSEC_ACTION");
+ if (user_msg == NULL) {
+ user_msg = read_from_user();
+ }
+ else{
+ leave_s = 1;
+ }
+
/* All the allowed actions */
switch(user_msg[0])
{
case 'i':
case 'I':
k_import(NULL);
- break;
+ break;
case 'l':
case 'L':
list_agents(0);
- break;
+ break;
case 'r':
case 'R':
remove_agent();
leave_s = 1;
break;
case 'V':
- print_version();
+ print_version();
break;
- default:
+ default:
printf("\n ** Invalid Action ** \n\n");
- break;
+ break;
}
if(leave_s)
{
- break;
+ break;
}
-
+
continue;
-
+
}
/* Checking if restart message is necessary */
printf("\n");
}
printf(EXIT);
-
+
return(0);
}