1 /* @(#) $Id: ./src/util/list_agents.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 "read-agents.h"
18 #define ARGV0 "list_agents"
23 printf("\nOSSEC HIDS %s: List available agents.\n", ARGV0);
24 printf("Available options:\n");
25 printf("\t-h This help message.\n");
26 printf("\t-a List all agents.\n");
27 printf("\t-c List the connected (active) agents.\n");
28 printf("\t-n List the not connected (active) agents.\n");
34 int main(int argc, char **argv)
36 char *dir = DEFAULTDIR;
37 char *group = GROUPGLOBAL;
47 /* Setting the name */
57 /* Getting the group name */
58 gid = Privsep_GetGroup(group);
59 uid = Privsep_GetUser(user);
62 ErrorExit(USER_ERROR, ARGV0, user, group);
66 /* Setting the group */
67 if(Privsep_SetGroup(gid) < 0)
69 ErrorExit(SETGID_ERROR,ARGV0, group);
73 /* Chrooting to the default directory */
74 if(Privsep_Chroot(dir) < 0)
76 ErrorExit(CHROOT_ERROR, ARGV0, dir);
80 /* Inside chroot now */
84 /* Setting the user */
85 if(Privsep_SetUser(uid) < 0)
87 ErrorExit(SETUID_ERROR, ARGV0, user);
91 if(strcmp(argv[1], "-h") == 0)
95 else if(strcmp(argv[1], "-a") == 0)
98 msg = "is available.";
100 else if(strcmp(argv[1], "-c") == 0)
105 else if(strcmp(argv[1], "-n") == 0)
108 msg = "is not active.";
112 printf("\n** Invalid option '%s'.\n", argv[1]);
117 agent_list = get_agents(flag);
120 char **agent_list_pt = agent_list;
124 printf("%s %s\n", *agent_list, msg);
128 free_agents(agent_list_pt);
132 printf("** No agent available.\n");