new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / addagent / manage_agents.h
old mode 100755 (executable)
new mode 100644 (file)
index 1110a01..4812dba
@@ -1,6 +1,3 @@
-/* @(#) $Id: ./src/addagent/manage_agents.h, 2011/09/08 dcid Exp $
- */
-
 /* Copyright (C) 2009 Trend Micro Inc.
  * All rights reserved.
  *
@@ -8,57 +5,58 @@
  * and/or modify it under the terms of the GNU General Public
  * License (version 2) as published by the FSF - Free Software
  * Foundation.
- *
- * License details at the LICENSE file included with OSSEC or
- * online at: http://www.ossec.net/en/licensing.html
  */
 
-
 #include "shared.h"
 #include "sec.h"
-
+#include "external/cJSON/cJSON.h"
 
 /** Prototypes **/
 
+/* b64 function prototypes */
+char *decode_base64(const char *src);
+char *encode_base64(int size, char *src);
+
 /* Read any input from the user (stdin) */
-char *read_from_user();
+char *read_from_user(void);
 
 /* Add or remove an agent */
-int add_agent();
-int remove_agent();
+int add_agent(int json_output);
+int remove_agent(int json_output);
+
 
 /* Extract or import a key */
-int k_extract(char *cmdextract);
-int k_import(char *cmdimport);
-int k_bulkload(char *cmdbulk);
+int k_extract(const char *cmdextract, int json_output);
+int k_import(const char *cmdimport);
+int k_bulkload(const char *cmdbulk);
 
 /* Validation functions */
-int OS_IsValidName(char *u_name);
-int OS_IsValidID(char *id);
-int IDExist(char *id);
-int NameExist(char *u_name);
-char *getFullnameById(char *id);
-char *OS_AddNewAgent(char *name, char *ip, char *id, char *key);
-
-
+int OS_IsValidName(const char *u_name);
+int OS_IsValidID(const char *id);
+int IDExist(const char *id);
+int NameExist(const char *u_name);
+char *IPExist(const char *u_name);
+char *getFullnameById(const char *id);
+char *OS_AddNewAgent(const char *name, const char *ip, const char *id);
+int  OS_RemoveAgent(const char *id);
+double OS_AgentAntiquity(const char *id);
+void FormatID(char *id);
 
 /* Print available agents */
-int print_agents(int print_status, int active_only, int csv_output);
+int print_agents(int print_status, int active_only, int csv_output, cJSON *json_output);
 int list_agents(int cmdlist);
 
-/* clear a line */
+/* Clear a line */
 char *chomp(char *str);
 
-
 /* Shared variables */
-int restart_necessary;
-int time1;
-int time2;
-int time3;
-int rand1;
-int rand2;
-fpos_t fp_pos;
-
+extern int restart_necessary;
+extern time_t time1;
+extern time_t time2;
+extern time_t time3;
+extern long int rand1;
+extern long int rand2;
+extern fpos_t fp_pos;
 
 /* Internal defines */
 #define USER_SIZE       514
@@ -73,7 +71,6 @@ fpos_t fp_pos;
 #define PRINT_AGENT         "   ID: %s, Name: %s, IP: %s\n"
 #define PRINT_AGENT_STATUS  "   ID: %s, Name: %s, IP: %s, %s\n"
 
-
 /* Add new agent */
 #define ADD_NEW         "\n- Adding a new agent"\
                         " (use '\\q' to return to the main menu).\n"\
@@ -84,9 +81,9 @@ fpos_t fp_pos;
 #define AGENT_INFO      "Agent information:\n   ID:%s\n   Name:%s\n   " \
                         "IP Address:%s\n\n"
 #define ADD_CONFIRM     "Confirm adding it?(y/n): "
-#define AGENT_ADD       "Agent added.\n"
+#define AGENT_ADD       "Agent added with ID %s.\n"
 #define ADDED           "Added.\n"
-#define ADD_NOT         "Not Adding ..\n"
+#define ADD_NOT         "Not Adding.\n"
 #define PRESS_ENTER     "** Press ENTER to return to the main menu.\n"
 #define MUST_RESTART    "\n** You must restart OSSEC for your changes" \
                         " to take effect.\n\n"
@@ -95,6 +92,7 @@ fpos_t fp_pos;
 #define ADD_ERROR_ID    "\n** ID '%s' already present. They must be unique.\n\n"
 #define ADD_ERROR_NAME  "\n** Name '%s' already present. Please enter a new name.\n\n"
 #define IP_ERROR        "\n** Invalid IP '%s'. Please enter a valid IP Address.\n\n"
+#define IP_DUP_ERROR    "\n** Duplicated IP '%s'. Please enter an unique IP Address.\n\n"
 #define NO_AGENT        "\n** No agent available. You need to add one first.\n"
 #define NO_ID           "\n** Invalid ID '%s' given. ID is not present.\n"
 #define NO_KEY          "\n** Invalid authentication key. Starting over again.\n"
@@ -106,7 +104,7 @@ fpos_t fp_pos;
 #define REMOVE_ID       "Provide the ID of the agent to be removed (or '\\q' to quit): "
 #define REMOVE_CONFIRM  "Confirm deleting it?(y/n): "
 #define REMOVE_DONE     "Agent '%s' removed.\n"
-#define REMOVE_NOT      "Not removing ..\n"
+#define REMOVE_NOT      "Not removing.\n"
 
 /* Import agent */
 #define IMPORT_KEY      "\n* Provide the Key generated by the server.\n" \
@@ -114,17 +112,17 @@ fpos_t fp_pos;
                         "*** OBS: Do not include spaces or new lines.\n\n" \
                         "Paste it here (or '\\q' to quit): "
 
-/* extract key */
+/* Extract key */
 #define EXTRACT_KEY     "Provide the ID of the agent to extract " \
                         "the key (or '\\q' to quit): "
 #define EXTRACT_MSG     "\nAgent key information for '%s' is: \n%s\n"
 
 
-/* Commom errors */
+/* Common errors */
 #define ERROR_KEYS      "Unable to handle keys file. Exiting.\n"
 #define EXTRACT_ERROR   "Unable to extract agent key.\n"
 #define INPUT_LARGE     ARGV0 ": Input too large. Not adding it.\n"
-#define EXIT            ARGV0 ": Exiting ..\n"
+#define EXIT            ARGV0 ": Exiting.\n"
 
 #define BANNER          "\n****************************************" \
                         "\n* %s %s Agent manager.     *" \
@@ -143,15 +141,10 @@ fpos_t fp_pos;
                         "Choose your action: I or Q: "
 
 /* WIN32 errors */
-#define CHDIR_ERROR     ARGV0 ": Could not chdir (%s) (Make sure path exists and executable is running with Administrative priviliges).\n"
-#define CONF_ERROR      ARGV0 ": Could not read (%s) (Make sure config exists and executable is running with Administrative priviliges).\n"
-#define COMPSEC_ERROR   ARGV0 ": Could not find cmd.exe using COMPSEC environment variable.\n"
-#define PROC_ERROR      ARGV0 ": Could not start process running command (%s).\n"
-#define RESULT_ERROR    ARGV0 ": Could not run command (%s) which returned (%ld).\n"
-#define CACLS_ERROR     ARGV0 ": Could not set permissions running (%s) which exited with (%ld).\n"
+#define CONF_ERROR      ARGV0 ": Could not read (%s) (Make sure config exists and executable is running with Administrative privileges).\n"
 #define GMF_ERROR       ARGV0 ": Could not run GetModuleFileName.\n"
 #define GMF_BUFF_ERROR  ARGV0 ": Could not get path because it is too long and was shrunk by (%d) characters with a max of (%d).\n"
-#define GMF_UNKN_ERROR  ARGV0 ": Could not run GetModuleFileName with returned (%ld).\n"
-#define AGENT_DELETE_ERROR    ARGV0 ": Could not unlink file (%s).\n"
+#define GMF_UNKN_ERROR  ARGV0 ": Could not run GetModuleFileName which returned (%ld).\n"
+
 
-/* EOF */
+int willchroot;