1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "read-agents.h"
14 #define ARGV0 "list_agents"
17 static void helpmsg(void) __attribute__((noreturn));
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");
31 int main(int argc, char **argv)
33 const char *dir = DEFAULTDIR;
34 const char *group = GROUPGLOBAL;
35 const char *user = USER;
51 /* Get the group name */
52 gid = Privsep_GetGroup(group);
53 uid = Privsep_GetUser(user);
54 if (uid == (uid_t) - 1 || gid == (gid_t) - 1) {
55 ErrorExit(USER_ERROR, ARGV0, user, group);
59 if (Privsep_SetGroup(gid) < 0) {
60 ErrorExit(SETGID_ERROR, ARGV0, group, errno, strerror(errno));
63 /* Chroot to the default directory */
64 if (Privsep_Chroot(dir) < 0) {
65 ErrorExit(CHROOT_ERROR, ARGV0, dir, errno, strerror(errno));
68 /* Inside chroot now */
72 if (Privsep_SetUser(uid) < 0) {
73 ErrorExit(SETUID_ERROR, ARGV0, user, errno, strerror(errno));
77 if (strcmp(argv[1], "-h") == 0) {
79 } else if (strcmp(argv[1], "-a") == 0) {
81 msg = "is available.";
82 } else if (strcmp(argv[1], "-c") == 0) {
85 } else if (strcmp(argv[1], "-n") == 0) {
87 msg = "is not active.";
89 printf("\n** Invalid option '%s'.\n", argv[1]);
93 agent_list = get_agents(flag);
95 char **agent_list_pt = agent_list;
98 printf("%s %s\n", *agent_list, msg);
102 free_agents(agent_list_pt);
104 printf("** No agent available.\n");