1 /* @(#) $Id: list_agents.c,v 1.7 2009/06/24 18:53:09 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 "read-agents.h"
17 #define ARGV0 "list_agents"
22 printf("\nOSSEC HIDS %s: List available agents.\n", ARGV0);
23 printf("Available options:\n");
24 printf("\t-h This help message.\n");
25 printf("\t-a List all agents.\n");
26 printf("\t-c List the connected (active) agents.\n");
27 printf("\t-n List the not connected (active) agents.\n");
33 int main(int argc, char **argv)
35 char *dir = DEFAULTDIR;
36 char *group = GROUPGLOBAL;
46 /* Setting the name */
56 /* Getting the group name */
57 gid = Privsep_GetGroup(group);
58 uid = Privsep_GetUser(user);
61 ErrorExit(USER_ERROR, ARGV0, user, group);
65 /* Setting the group */
66 if(Privsep_SetGroup(gid) < 0)
68 ErrorExit(SETGID_ERROR,ARGV0, group);
72 /* Chrooting to the default directory */
73 if(Privsep_Chroot(dir) < 0)
75 ErrorExit(CHROOT_ERROR, ARGV0, dir);
79 /* Inside chroot now */
83 /* Setting the user */
84 if(Privsep_SetUser(uid) < 0)
86 ErrorExit(SETUID_ERROR, ARGV0, user);
90 if(strcmp(argv[1], "-h") == 0)
94 else if(strcmp(argv[1], "-a") == 0)
97 msg = "is available.";
99 else if(strcmp(argv[1], "-c") == 0)
104 else if(strcmp(argv[1], "-n") == 0)
107 msg = "is not active.";
111 printf("\n** Invalid option '%s'.\n", argv[1]);
116 agent_list = get_agents(flag);
119 char **agent_list_pt = agent_list;
123 printf("%s %s\n", *agent_list, msg);
127 free_agents(agent_list_pt);
131 printf("** No agent available.\n");