1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
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
7  * Foundation
8  */
9 
10 #include "setup-shared.h"
11 #include "os_xml/os_xml.h"
12 
13 #define OSSEC_CONFIG_TMP  ".tmp.ossec.conf"
14 
15 
16 /* Enable Syscheck */
main(int argc,char ** argv)17 int main(int argc, char **argv)
18 {
19     char *status;
20     const char *(xml_syscheck_status[]) = {"ossec_config", "syscheck", "disabled", NULL};
21 
22     if (argc < 3) {
23         printf("%s: Invalid syntax.\n", argv[0]);
24         printf("Try: '%s <dir> [enable|disable]'\n\n", argv[0]);
25         return (0);
26     }
27 
28     /* Check for directory */
29     if (chdir(argv[1]) != 0) {
30         printf("%s: Invalid directory: '%s'.\n", argv[0], argv[1]);
31         return (0);
32     }
33 
34     /* Check if OSSEC-HIDS was installed already */
35     if (!fileexist(OSSECCONF)) {
36         printf("%s: OSSEC not installed yet. Exiting.\n", argv[0]);
37         return (0);
38     }
39 
40     /* Check status */
41     if (strcmp(argv[2], "enable") == 0) {
42         status = "no";
43     } else {
44         status = "yes";
45     }
46 
47     /* Write to the config file */
48     if (OS_WriteXML(OSSECCONF, OSSEC_CONFIG_TMP, xml_syscheck_status,
49                     "no", status) != 0) {
50         printf("%s: Error writing to the Config file. Exiting.\n", argv[0]);
51         return (0);
52     }
53 
54     /* Rename config files */
55     unlink(OSSECLAST);
56     rename(OSSECCONF, OSSECLAST);
57     rename(OSSEC_CONFIG_TMP, OSSECCONF);
58 
59     return (0);
60 }
61